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 −

' ' in 'python' ?

A - 'python'

B - False

C - Name error

D - True

Answer : D


To strings connected by ‘in’ operator gives true and false.

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 - How can we generate random numbers in python using methods?

A - random.uniform ()

B - random.randint()

C - random.random()

D - All of the above

Answer : D


To generate random numbers we import random module and in that module we have these methods/functions.

uniform(x,y) returns a floating number in the range [x,y] random() returns a floating point number in the range [0, 1].

randint(x,y) returns a random integer number in the range [x, y].

Answer : B


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 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 - What happens in the below code?

class A: 
   def __init__(self, i=100): 
class B(A): 
   def __init__(self,j=0): 
def main(): 
   b= B() 

A - Class B inherits all the data fields of class A.

B - Class B needs an Argument.

C - The data field ‘j’ cannot be accessed by object b.

D - Class B is inheriting class A but the data field ‘i’ in A cannot be inherited.

Answer : D


Reason being that i is initiated with self thus making it a instantiate variable of that class which cannot be inherited by the above way.

Q 7 - Discuss the outcome of the code?

def func1(n): 
      return 0 
def func2(n, result): 
      return(func2(n-1, n+result))  

A - Func1 is tail recursion.

B - Func1 and Func2 are tail recursions.

C - Func2 is only tail recursion.

D - Neither Func2 nor Func1 is tail recursion.

Answer : B


A function call is said to be tail recursive if there is nothing to do after the function returns except return its value.

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

A - Encode()

B - Decode()

C - Convert()

D - tostring()

Answer : B


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

Q 9 - Using the pack manager, how you can you put the components in a container in the same row?

A - Component.pack(side= ''LEFT'')

B - Component.pack(''Left '')

C - Component.pack(side=LEFT)

D - Component.pack(Left-side)

Answer : C


It is the default way to do this.

Q 10 - Which is the special symbol used in python to add comments?

A - $

B - //

C - /*.... */

D - #

Answer : D