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 −

a = ['he', 'she', 'we']

' '.join(a)

A - ['heshewe']

B - 'heshewe'

C - ['he she we']

D - 'he she we'

Answer : B

Explanation

The method join() takes list of string as input and returns string as output. It removes ', ' and add the given string with join to the list.

Q 2 - What is output of following code −

num=3
while True:
   if (num%0o12 == 0):
      break
print(num)
num += 1

A - 3 4 5 6 7 8 9 10 11 12

B - 3 4 5 6 7 8 9

C - 3 4 5 6 7 8 9 10 11

D - None of the above

Answer : B

Explanation

we are getting output 3 to 9 because 0o12 is octal number.

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

Explanation

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 - What is output of following code −

s = ''mnopqr ''
i = ''m ''
while i in s:
   print('i', end= '' '')

A - i i i i i i i i..

B - m m m m m ..

C - m n o p q r

D - no output

Answer : A

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

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

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

Explanation

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 - 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 : C

Explanation

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 - Which is the special symbol used in python to add comments?

A - $

B - //

C - /*.... */

D - #

Answer : D

python_questions_answers.htm
Advertisements