Python Online Quiz


Advertisements

Following quiz provides Multiple Choice Questions (MCQs) related to Python. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - What is output of −

33 == 33.0

A - False

B - True

C - 33

D - None of the above

Answer : B

Explanation

comparison operator evaluates true and false. And in python we need not specify whether the number is int or float.

Q 2 - What is output for following code −

y = [4, 5,1j]
y.sort()

A - [1j,4,5]

B - [5,4,1j]

C - [4,5,1j]

D - Type Error

Answer : D

Explanation

we cannot compare complex numbers with numbers, so the output results in type error stating that complex numbers cannot be compared with <,>,=.

Q 3 - Select the option for following code −

s = 0
for d in range(0, 5, 0.1):
… s += d
… print(s)

A - Syntax Error

B - Type Error

C - Runtime Error

D - Both b & c

Answer : D

Explanation

we will get type error during runtime as float object cannot be interpreted as integer. Here 0.1 is the float value.

Answer : B

Explanation

If A is proper subset of B then hen all elements of A are in B but B contains at least one element that is not in B.

Q 5 - What is the output of the code?

def f():
   global z
   print('z is: ', z)
   z=50
   print('new value of global z is: ', z)

f()
   print('Value of z is: ', z)

A - z is 100

new value of global z is: 100

value of z is 100

B - z is 100

new value of global z is: 100

value of z is 50

C - z is 100

new value of global z is: 50

value of z is 100

D - z is 100

new value of global z is: 50

value of z is 50

Answer : D

Explanation

Here in the above code ‘global’ keyword is used to state that ‘z’ is global variable. So when we assign a value to z in the function then the new assigned value is reflected whenever we use the value of ‘z’ in the main block or outside the function.

Q 6 - What is the output of the following code?

eval(''1 + 3 * 2'')

A - ‘1+6’

B - ‘4*2’

C - ‘1+3*2’

D - 7

Answer : D

Explanation

Eval is a method used to evaluate the values entered in the braces.

Q 7 - Which options are correct to create an empty set in Python?

A - {}

B - ()

C - []

D - set()

Answer : D

Explanation

we need to define the set by including the keyword ‘set’.

Answer : D

Explanation

You need to define the format in which you want to open the file. Proper path has to be declared by the user for the interpreter to reach the destination of the file.

Q 9 - Suppose you are using a grid manager then which option is best suitable to place a component in multiple rows and columns?

A - Columnspan and rowspan

B - Only row

C - Only column

D - Only rowspan

Answer : A

Q 10 - What is the value of a, b, c in the given below code?

a, b = c = 2 + 2, ''TutorialsPoint''

A - a=4, 'TutorialsPoint'

b= 4, 'TutorialsPoint'

c= 4, 'TutorialsPoint'

B - a=2

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

C - a=4

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

D - a=4

b= 'TutorialsPoint'

c= NULL.

Answer : C

python_questions_answers.htm
Advertisements