Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

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

Explanation

To strings connected by in' operator gives true and false.

Q 2 - What is output for −

b = [11,13,15,17,19,21]

ptint(b[::2])

A - [19,21]

B - [11,15]

C - [11,15,19]

D - [13,17,21]

Answer : C

Explanation

b[::2] :- it iterates over the list with 2' increments

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(n):
   if(n==1):
      return 1;
   else:
      return(n+func(n-1))
print(func(4))

A - 12

B - 10

C - 9

D - 11

Answer : B

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 - Which among them is used to create an object?

A - A class

B - A function

C - A method

D - A constructor

Answer : D

Explanation

constructor is used to create an object of class.

Answer : B, C, D.

Explanation

Recursive function is used to make the code simpler. They are better version of non-recursive functions.

Q 8 - Which function can be used on the file to display a dialog for saving a file?

A - Filename = savefilename()

B - Filename = asksavefilename()

C - Fielname = asksaveasfilename()

D - No such option in python.

Answer : C

Explanation

This is the default method to display a dialog for saving a file in Tkinter module of Python.

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

python_questions_answers.htm
Advertisements