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 −

raining'. find('z') ?

A - Type error

B - ' '

C - -1

D - Not found

Answer : C

Explanation

If the string is not found by method find() , it returns the integer -1.

Q 2 - What is the output of following code −

[ (a,b) for a in range(3) for b in range(a) ]

A - [ (1,0),(2,1),(3,2)]

B - [ (0,0),(1,1),(2,2)]

C - [(1,0),(2,1),(2,1)]

D - [ (1,0),(2,0),(2,1)]

Answer : D

Explanation

This is nested for loop. The output of first for loop will be the value for the next loop.

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 for − min(''hello world'')

A - e

B - a blank space character

C - w

D - None of the above.

Answer : B

Explanation

python considers a blank space character as minimum value in a string.

Q 5 - What is the output of the code?

def f():
   global z
   print('z is: ', z)
   z=50
   print('new value of global z is: ', z)

f()
   print('Value of z is: ', z)

A - z is 100

new value of global z is: 100

value of z is 100

B - z is 100

new value of global z is: 100

value of z is 50

C - z is 100

new value of global z is: 50

value of z is 100

D - z is 100

new value of global z is: 50

value of z is 50

Answer : D

Explanation

Here in the above code ‘global' keyword is used to state that ‘z' is global variable. So when we assign a value to z in the function then the new assigned value is reflected whenever we use the value of ‘z' in the main block or outside the function.

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

eval(''1 + 3 * 2'')

A - ‘1+6'

B - ‘4*2'

C - ‘1+3*2'

D - 7

Answer : D

Explanation

Eval is a method used to evaluate the values entered in the braces.

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.

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 module is used in python to create Graphics?

A - Turtle

B - Canvas

C - Tkinter

D - Graphics

Answer : A

python_questions_answers.htm
Advertisements