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

'Tutorials Point' [100:200]?

A - Index error.

B - ' '

C - 'Tutorials Point'

D - Syntax error

Answer : B


Slicing will never give us an error even if we give it too large of an index for the string. It will just return the widest matching slice it can.

Q 2 - What is output for −

b = [11,13,15,17,19,21]


A - [19,21]

B - [11,15]

C - [11,15,19]

D - [13,17,21]

Answer : C


b[::2] :- it iterates over the list with ‘2’ increments

Q 3 - When the given code is executed how many times ' 'you are learning python ' ' will be printed.

a = 0
while a<10:
… print(''you are learning python'')
… pass

A - 9

B - 10

C - 11

D - Infinite number of times.

Answer : D


The loop will execute infinite number of times because there is no statement specified for end of loop and pass indicates nothing is to be done.

Q 4 - How can we check whether the object is instance of class or not. Let us consider an object O which is instance of class B.

A - B.isinstance(O)

B - O.isinstance(B)

C - isinstance(O,B)

D - isinstance(B,O)

Answer : C


isinstance() method is used to find whether the object is instance of class or not.

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

def nprint(message, n):
while(n > 0):
nprint('z', 5)

A - zzzz

B - zzzzz

C - Syntax Error

D - Infinite Loop

Answer : D


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

Q 6 - Analyze the given below code?

class Demo: 
   def __init__(self,d): 
   def print(self): 
a = Demo(''Hello'') 

A - You cannot use print(self) as a function name.

B - Program has an error because class A does not have a constructor.

C - Program will print ‘Hello’ if we change print(d) to print(self.d).

D - Syntax Error.

Answer : C


D stores the argument value here. Thus when we call the class ‘‘Hello’’ is passed as an argument which is stored in the variable d.

Answer : C


+ Operator cannot be operated on the sets.

Q 8 - Which code is used to open a file for binary writing?

A - ''w''

B - ''wb''

C - ''r+''

D - ''a''

Answer : B


‘b’ format is used to work on the binary format of file.