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 −

'search'. find('S') ?

A - s

B - -1

C - ‘ ‘

D - None of the above

Answer : B

Explanation

The method find() is case sensitive.

Q 2 - Which of the following is false statement in python

A - int(144)==144

B - int('144')==144

C - int(144.0)==144

D - None of the above

Answer : D

Explanation

The built-in int() type constructor converts string and floating value to integer.

Q 3 - Name the error that doesn't cause program to stop/end, but the output is not the desired result or is incorrect.

A - Syntax error

B - Runtime error

C - Logical error

D - All of the above

Answer : C

Explanation

logical error doesn't cause the program to stop/end, but the output is not the desired result or is incorrect.

Q 4 - How can we check whether the object is instance of class or not. Let us consider an object O which is instance of class B.

A - B.isinstance(O)

B - O.isinstance(B)

C - isinstance(O,B)

D - isinstance(B,O)

Answer : C

Explanation

isinstance() method is used to find whether the object is instance of class or not.

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

import math
 
   def main():
      math.cos(math.pi)
main()
   print(main())

A - -1

B - None

C - Error

D - Math.pi not defined

Answer : B

Explanation

None is printed because function does not return the value.

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

def f(x = 100, y = 100): 
   return(x+y, x-y) 
x, y = f(y = 200, x = 100) 
print(x, y) 

A - 300 -100

B - 200 0

C - 200 100

D - 0 300

Answer : A

Explanation

In variable y functions runs and gives the output of x + y and x - y i.e 300 and -100 respectively. Then assignment operator is used to assign the value of x and y.

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.

Answer : C

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