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 - Name the python module which supports regular expressions.

A - regex

B - re

C - pyre

D - pyregex

Answer : B


re is the module which supports regular expressions and is part of standard library.

We can import re module as − import re.

Q 3 - Syntax error in python is detected by _________at _______

A - compiler/ compile time

B - interpreter/ run time

C - compiler/ run time

D - interpreter/ compile time

Answer : B


Syntax error in python is detected by interpreter at run time.

Answer : C


since there is no such element in the set, so key error is raised.

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.

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

A - {}

B - ()

C - []

D - set()

Answer : D


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

Answer : C


For the type of message user want to display on the window of python there is a type of code according to it. Example for warning message user choose showwarning method.

Q 10 - What will be the output of the following code?

minidict = { 'name': 'TutorialsPoint', 'name': 'website'}

A - TutorialsPoint

B - Website

C - ('TutorialsPoint' , 'website')

D - It will show an Error.

Answer : B


Dictionary gets updated by the above code as the key has been assigned a new value.