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 −

'you are doing well' [2:999]

A - 'you are doing well'

B - ' '

C - Index error.

D - 'u are doing well'

Answer : D

Explanation

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

x = 2
y = 10
x * = y * x + 1

A - 42

B - 41

C - 40

D - 39

Answer : A

Explanation

x * = y * x + 1 means x = x * (y * x + 1)

Q 3 - Pylab is a package that combine _______,________&______ into a single namespace.

A - Numpy, scipy & matplotlib

B - Numpy, matplotlib & pandas

C - Numpy, pandas & matplotlib

D - Numpy, scipy & pandas

Answer : A

Explanation

pylab package in python combines numpy, scipy & matplotlib into a single namespace.

Q 4 - What is output of following code −

def func(x, ans):
   if(x==0):
      return 0
   else: 
      return func(x-1, x+ans) 
print(func(2,0))

A - 0

B - 1

C - 2

D - 3

Answer : A

Q 5 - What is output of following −

print(''abbzxyzxzxabb''.count(abb',-10,-1))

A - 2

B - 0

C - 1

D - Error

Answer : B

Explanation

It Counts the number of times the substring abb' is present starting from position 2 and ending at position 11 in the given string.

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

s = ''\t\t\t\n\nTutorialsPoint\n\n\n\t\t\t''
s.strip()

A - '\n\nTutorialsPoint\n\n\n'

B - '\t\t\tTutorialsPoint\t\t\t'

C - 'TutorialsPoint'

D - 'TutorialsPoint' , '\t\t\t\n\n \n\n\n\t\t\t'

Answer : C

Explanation

Strip method is used to remove all the newline and tab spaces code in the string.

Q 7 - Discuss the outcome of the code?

def func1(n): 
   if(n==0): 
      return 0 
   else: 
      return(n+func1(n-1)) 
def func2(n, result): 
   if(n==0): 
      return(result) 
   else: 
      return(func2(n-1, n+result))  
print(func1(4)) 
print(func2(4,0)) 

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

Explanation

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 - Select the correct function among them which can be used to write the data to perform for a binary output?

A - Write

B - Output.binary

C - Dump

D - Binary.output

Answer : C

Q 9 - Which way among them is used to create an event loop ?

A - Window.eventloop()

B - Window.mainloop()

C - Window.loop()

D - Eventloop.window()

Answer : B

Q 10 - Which can be an Identifier among them in Python?

A - 1abc

B - $12a

C - _xy1

D - @python

Answer : C

Explanation

Because Identifiers start from letter A to Z or a to z or an underscore (_) followed by more letters or zero or underscores and digits (0 to 9). Python does not allow @ or $ or % within the identifier.

python_questions_answers.htm
Advertisements