Python Online Quiz



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 for −

'search'. find('S') ?

A - s

B - -1

C -

D - None of the above

Answer : B

Explanation

The method find() is case sensitive.

Q 2 - What is output of following code −

a = (1, 2)
a[0] +=1

A - (1,1,2)

B - 2

C - Type Error

D - Syntax Error

Answer : C

Explanation

TypeError − tuple' object does not support item assignment because a tuple is immutable.

Q 3 - Which operator is right-associative

A - *

B - =

C - +

D - %

Answer : B

Explanation

= operator is right associative as assignment operators are right associative.

Q 4 - What is output for −

2 * 2 **3

A - 12

B - 64

C - 16

D - 36

Answer : C

Explanation

2**3 gives 2*2*2 i.e. 8, then 2*8 gives 16, since order of precedence is ** then*. ** implies raise to power''.

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

def nprint(message, n):
while(n > 0):
   print(message)
n-=1
nprint('z', 5)

A - zzzz

B - zzzzz

C - Syntax Error

D - Infinite Loop

Answer : D

Explanation

Because decrementing condition of n' is not present in the while loop.

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.

Answer : C

Explanation

+ Operator cannot be operated on the sets.

Q 8 - Which method is used to convert raw byte data to a string?

A - Encode()

B - Decode()

C - Convert()

D - tostring()

Answer : B

Explanation

Decode is the method used to convert the raw byte data to a string.

Answer : C

Explanation

Button keyword is used to make a button in Python. To set the process button in command we assign the value processButton in the command. Any text value can be given to the button which is assigned under text keyword.

Q 10 - Which module is used in python to create Graphics?

A - Turtle

B - Canvas

C - Tkinter

D - Graphics

Answer : A

python_questions_answers.htm
Advertisements