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

33 == 33.0

A - False

B - True

C - 33

D - None of the above

Answer : B

Explanation

comparison operator evaluates true and false. And in python we need not specify whether the number is int or float.

Q 2 - What is output for following code −

y = [4, 5,1j]
y.sort()

A - [1j,4,5]

B - [5,4,1j]

C - [4,5,1j]

D - Type Error

Answer : D

Explanation

we cannot compare complex numbers with numbers, so the output results in type error stating that complex numbers cannot be compared with <,>,=.

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 - 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 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 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.

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 code is used to open a file for binary writing?

A - ''w''

B - ''wb''

C - ''r+''

D - ''a''

Answer : B

Explanation

b' format is used to work on the binary format of file.

Q 9 - Select the correct option to draw a rectangle centred at 50,50 with width and height as 50, 70 respectively.

A - Canvas.create_rect(50,50,50,70)

B - Canvas.create_rect(50,70,50,50)

C - Canvas.create_rectangle(50,50,50,70)

D - Tkinter.create_rect(50,50,50,70)

Answer : C

Q 10 - Best part is you can display images in various options in Python. Select the option where you can display an image −

A - Only A label

B - Only A button and A label

C - Only A checkbox

D - A label, a check box , a button and a radio button.

Answer : D

python_questions_answers.htm
Advertisements