Python Programming Practice Quiz! Exam

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Bscit_it
B
Bscit_it
Community Contributor
Quizzes Created: 6 | Total Attempts: 3,485
| Attempts: 204 | Questions: 40
Please wait...
Question 1 / 40
0 %
0/100
Score 0/100
1. What is the output when following statement is executed ?
  1. >>>"a"+"bc"
 

Explanation

The output of the given statement "a" + "bc" is "abc". This is because the "+" operator is used for concatenation in Python, which means it combines two strings together. In this case, the string "a" is combined with the string "bc" to form the resulting string "abc".

Submit
Please wait...
About This Quiz
Python Programming Practice Quiz! Exam - Quiz

The 'Python Programming Practice Quiz! Exam' is designed to test your understanding of Python syntax and concepts. It covers topics like case sensitivity, variable naming, operators, and division... see moremethods, enhancing your coding skills and preparation for programming challenges. see less

2. Which of the following data types is not supported in python?  

Explanation

Generics is not a supported data type in Python. Generics are commonly used in statically typed languages like Java and C# to define classes, interfaces, or methods that can work with different types of data. However, Python is a dynamically typed language, which means that variables can hold values of any type without explicitly specifying the type. Therefore, generics are not necessary in Python and are not supported as a built-in data type.

Submit
3. Which of the following function checks in a string that all characters are whitespaces?  

Explanation

The function isspace() is used to check whether all characters in a string are whitespaces. It returns True if all characters are whitespaces, otherwise, it returns False. This function is useful when we want to validate if a string contains only spaces or not.

Submit
4. What is the output of the following code ?
  1. >>>example = "snow world"
  2. >>>print("%s" % example[4:7])
 

Explanation

The code is using string slicing to extract a portion of the "example" string starting from index 4 and ending at index 7 (exclusive). In the "example" string, the characters at index 4, 5, and 6 are "w", "o", and "r" respectively. So, the output will be "wo".

Submit
5. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
    print(i)
 

Explanation

The output of the given code is 0 1 2 3.

The code initializes a variable x with the string 'abcd'. It then iterates over the range of the length of x, which is 4 in this case. During each iteration, it prints the value of i, which starts from 0 and goes up to 3. Therefore, the output will be 0 1 2 3, each value on a separate line.

Submit
6. Which one of these is floor division?

Explanation

The double forward slash (//) is the floor division operator in Python. Floor division returns the largest whole number that is less than or equal to the division of two numbers. It discards the decimal part of the result and only returns the integer value. This is different from the regular division operator (/) which returns a floating-point number. The percent sign (%) is the modulus operator, used to calculate the remainder of a division operation. Therefore, the correct answer is // as it represents floor division.

Submit
7. Who created Python?

Explanation

Guido van Rossum is the creator of Python. He developed the programming language in the late 1980s and released the first version in 1991. Python was designed to be easy to read and write, with a focus on simplicity and code readability. It has since become one of the most popular programming languages in the world, known for its versatility and extensive libraries.

Submit
8.  Which of the following expressions is an example of type conversion?
 

Explanation

The expression 4.0 + float(3) is an example of type conversion because the integer 3 is being explicitly converted to a float using the float() function. This allows for the addition of a float (4.0) and an integer (3) by converting the integer to a float before performing the addition operation.

Submit
9. Which of the following expressions results in an error?

Explanation

The expression int('10.8') results in an error because the int() function is used to convert a value to an integer, but '10.8' is a string that cannot be directly converted to an integer.

Submit
10. Which of the following is correct about Python?

Explanation

Python is a versatile programming language that is high-level, interpreted, interactive, and object-oriented. It is designed to prioritize readability, using English keywords instead of punctuation and having fewer syntactical constructions compared to other languages. Therefore, all of the statements provided are correct about Python.

Submit
11. Which is the correct operator for power(x^y)?

Explanation

The correct operator for power(x^y) is X**y. This is the exponentiation operator in Python, which raises the value of x to the power of y. It is commonly used to perform calculations involving exponentiation. The other options mentioned (X^y and X^^y) are not valid operators for exponentiation in Python.

Submit
12.  What is the output of the following?
x = 'abcd'
for i in x:
    print(i.upper())
 

Explanation

The given code iterates through each character in the string 'abcd' and prints the uppercase version of each character. So, the output will be 'A B C D'.

Submit
13. Which of the following is an invalid statement?

Explanation

The statement "a b c = 1000 2000 3000" is an invalid statement because variable names cannot contain spaces.

Submit
14. Which one of the following has the highest precedence in the expression?

Explanation

Parentheses have the highest precedence in an expression. This means that any operations within parentheses should be performed first before any other operations in the expression. This is because parentheses are used to group certain parts of an expression together, indicating that those operations should be done first. By giving parentheses the highest precedence, it ensures that the operations within them are prioritized and evaluated before any other operations in the expression.

Submit
15. What is the value of the expression:
float(4+int(2.39)%2)
 

Explanation

The expression first calculates the value of int(2.39) which is 2. Then it calculates 4 + 2 % 2 which is equal to 4. Finally, the float() function is used to convert the result to a floating-point number, resulting in 4.0.

Submit
16. Python programs are executed by:

Explanation

Python programs are executed by an interpreter. An interpreter is a program that reads and executes code line by line. It translates the code into machine language instructions and immediately executes them. This allows for a more interactive and flexible programming experience, as the interpreter can execute code on the go and provide immediate feedback. In contrast, a compiler translates the entire code into machine language instructions before execution, resulting in a standalone executable file. An assembler, on the other hand, is used for low-level programming languages like assembly language.

Submit
17. If there is a  ___ error in the program, it will run without generating error messages but it will not give the desired result.

Explanation

A semantic error is a type of error in programming where the code is syntactically correct but does not produce the desired result. This means that the program will run without any error messages, but the output or behavior of the program will be incorrect. In other words, there is a logical mistake in the code that leads to incorrect execution. Therefore, if there is a semantic error in the program, it will run without generating error messages but will not give the desired result.

Submit
18. What is the output when following code is executed ?
  1. >>>str1="helloworld"
  2. >>>str1[::-1]
 

Explanation

The given code is using slicing with a step value of -1 to reverse the string "helloworld". When a negative step value is used, the slicing starts from the end of the string and goes towards the beginning. So, the output of the code will be "dlrowolleh", which is the reversed version of "helloworld".

Submit
19. Which of the following is an invalid variable?

Explanation

The variable "1st_string" is invalid because variable names cannot start with a number in most programming languages. Variable names must start with a letter or an underscore.

Submit
20. Which of the following is correct about Python?

Explanation

Python supports automatic garbage collection, which means that the memory management is handled automatically by the language itself. This helps in freeing up memory that is no longer in use, making the programming process more efficient and less prone to memory leaks. Additionally, Python can be easily integrated with various other programming languages and technologies such as C, C++, COM, ActiveX, CORBA, and Java. This allows developers to leverage existing code and libraries in their Python projects, making it a versatile and flexible language for software development.

Submit
21. What is the answer to this expression, 22 % 3 is?

Explanation

The expression 22 % 3 represents the remainder when 22 is divided by 3. In this case, 22 can be divided by 3 evenly with a remainder of 1. Therefore, the answer to the expression 22 % 3 is 1.

Submit
22. Which one of the following is used for indexing in the python program?

Explanation

Brackets [ ] are used for indexing in a Python program. In Python, indexing is used to access individual elements or a range of elements in a sequence like a string, list, or tuple. By using brackets [ ] with an index value inside, we can retrieve the desired element from the sequence. The index value starts from 0 for the first element, and negative indexing can also be used to access elements from the end of the sequence. Therefore, the correct answer is brackets [ ].

Submit
23.  Given a string example="hello" what is the output of example.count(l)
 

Explanation

The output of example.count(l) is 2 because the count() method in Python returns the number of occurrences of a specified substring in a string. In this case, "l" appears twice in the string "hello".

Submit
24. The following is displayed by a print function call:
  1. tom
  2. dick
  3. harry
Select all of the function calls that result in this output

Explanation

The correct answer is print(‘tomdickharry’). This function call includes line breaks (\n) between each name, resulting in each name being displayed on a separate line.

Submit
25. What arithmetic operators cannot be used with strings ?
 

Explanation

The arithmetic operator "-" cannot be used with strings. This is because the "-" operator is used for subtraction and it does not have any meaning when applied to strings. Strings can be concatenated using the "+" operator, repeated using the "*" operator, but subtraction is not a valid operation for strings.

Submit
26. What is the output of the following?
for i in range(2.0):
    print(i)
 

Explanation

The code will throw an error because the range() function does not accept float values as arguments. The range() function can only accept integer values.

Submit
27. What is the output when following code is executed ?
  1. >>> str1 = 'hello'
  2. >>> str1[-1:]

Explanation

The code is using negative indexing to access the last character of the string "hello". The syntax str1[-1:] means to start from the last character and go until the end of the string. Therefore, the output will be "o", which is the last character of the string "hello".

Submit
28. What is the type of inf?
 

Explanation

The correct answer is integer because "inf" is a common abbreviation for infinity, which is a concept in mathematics. In programming, infinity is often represented as a special value of the data type float or double. However, in this case, the question specifically asks for the "type" of inf, and since inf is not a variable or a specific value, it doesn't have a data type. Therefore, the answer is integer because inf is not a boolean, float, or complex number.

Submit
29. Is Python case sensitive when dealing with identifiers?

Explanation

Python is case sensitive when dealing with identifiers. This means that the uppercase and lowercase letters are considered as distinct characters. For example, variables named "myVariable" and "myvariable" are treated as two different variables in Python. Therefore, it is important to be consistent with the casing of identifiers while coding in Python.

Submit
30. Following a set of commands are executed in shell, what will be the output?
  1. >>>str="hello"
  2. >>>str[:2]
  3. >>>

Explanation

The output will be "he" because the command "str[:2]" is slicing the string "hello" from index 0 to index 2 (exclusive), which gives us the substring "he".

Submit
31. What is the output of the following code ?
  1. >>>example = "snow world"
  2. >>>example[3] = 's'
  3. >>>print example
 

Explanation

The code will produce an error. This is because strings in Python are immutable, meaning they cannot be changed once they are created. Therefore, trying to assign a new value to a specific index of a string will result in an error.

Submit
32.  What is the output of the following code ?
  1. >>>example = "helle"
  2. >>>example.find("e")
 

Explanation

The output of the code is 1. The find() method in Python returns the index of the first occurrence of the specified substring within the given string. In this case, the substring "e" is found at index 1 in the string "helle". Therefore, the output is 1.

Submit
33. What is the output when following statement is executed ?
  1. >>>print('new' 'line')
 

Explanation

The given statement will output "new line". This is because the print function will print the string 'new' and then move to a new line to print the string 'line'. Therefore, the output will be "new line".

Submit
34. What is the output of the following?
True = False
while True:
    print(True)
    break

Explanation

The output of the given code is "None". This is because the code assigns the value of False to the variable True, which is not allowed in Python. However, since the code breaks out of the while loop immediately after the first iteration, the print statement is never executed. Therefore, there is no output and the value of the code is None.

Submit
35. What is the result of cmp(3, 1)?
 

Explanation

The result of cmp(3, 1) is 1 because cmp() is a built-in function in Python that compares two objects and returns -1 if the first object is less than the second, 0 if they are equal, and 1 if the first object is greater than the second. In this case, 3 is greater than 1, so the result is 1.

Submit
36.  What is the output of the following?
x = ['ab', 'cd']
for i in x:
    i.upper()
print(x)
 

Explanation

The output of the code is [‘ab’, ‘cd’] because the code is iterating over each element in the list x and applying the upper() method to each element. However, the upper() method returns a new string with all lowercase characters converted to uppercase, but it does not modify the original string. Therefore, the original list x remains unchanged and the output is still [‘ab’, ‘cd’].

Submit
37. All keywords in Python are in?

Explanation

In Python, keywords are reserved words that have predefined meanings and cannot be used as variable names or identifiers. They are always written in lowercase. Therefore, the correct answer is "lower case."

Submit
38. Carefully observe the code and give the answer.
  1. def example(a):
  2.     a = a + '2'
  3.      a = a*2
  4.     return a
  5. >>>example("hello")

Explanation

The code is missing proper indentation. This results in an indentation error when the code is executed.

Submit
39. What is the output of the following code ?
  1. >>>max("what are you")

Explanation

The code is attempting to find the maximum value in the string "what are you". However, since the max() function is being used on a string, it will return the character with the highest ASCII value, which in this case is "y".

Submit
40. What is the average value of the code that is executed below?
  1. >>>grade1 = 80
  2. >>>grade2 = 90
  3. >>>average = (grade1 + grade2) / 2

Explanation

The given code calculates the average value of two grades, grade1 and grade2. It adds the two grades together and then divides the sum by 2. Therefore, the average value is 85.1.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 17, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 01, 2017
    Quiz Created by
    Bscit_it
Cancel
  • All
    All (40)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the output when following statement is executed ?...
Which of the following data types is not supported in python?  
Which of the following function checks in a string that all characters...
What is the output of the following code ? >>>example =...
What is the output of the following? x = 'abcd' ...
Which one of these is floor division?
Who created Python?
 Which of the following expressions is an example of type...
Which of the following expressions results in an error?
Which of the following is correct about Python?
Which is the correct operator for power(x^y)?
 What is the output of the following? x = 'abcd' ...
Which of the following is an invalid statement?
Which one of the following has the highest precedence in the...
What is the value of the expression: float(4+int(2.39)%2) 
Python programs are executed by:
If there is a  ___ error in the program, it will run without...
What is the output when following code is executed ?...
Which of the following is an invalid variable?
Which of the following is correct about Python?
What is the answer to this expression, 22 % 3 is?
Which one of the following is used for indexing in the python program?
 Given a string example="hello" what is the output of...
The following is displayed by a print function call: ...
What arithmetic operators cannot be used with strings ? 
What is the output of the following? for i in range(2.0): ...
What is the output when following code is executed ? >>> str1...
What is the type of inf? 
Is Python case sensitive when dealing with identifiers?
Following a set of commands are executed in shell, what will be the...
What is the output of the following code ? >>>example =...
 What is the output of the following code ? >>>example =...
What is the output when following statement is executed ?...
What is the output of the following? True = False ...
What is the result of cmp(3, 1)?  
 What is the output of the following? x = ['ab',...
All keywords in Python are in?
Carefully observe the code and give the answer. ...
What is the output of the following code ? >>>max("what...
What is the average value of the code that is executed below? ...
Alert!

Advertisement