Loading, please wait...

Python Multiple Choice Questions And Answers

Search here for MCQs

Are you preparing for the next job interviews? If yes, trust me this post will help you also we'll suggest you check out a big collection for Programming Full Forms that may help you in your interview:

List of Programming Full Forms 

21. Which function overloads the + operator?

Refer documentation.
  • __add__()
  • __plus__()
  • __sum__()
  • none of the mentioned

22. Which operator is overloaded by __invert__()?

__invert__() overloads ~.
  • !
  • ~
  • ^

23. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?

The function __add__() is called first since it is within the bracket. The function __str__() is then called on the object that we received after adding A and B.
  • __add__(), __str__()
  • __str__(), __add__()
  • __sum__(), __str__()
  • __str__(), __sum__()

24. What will be the output of the following Python code?

class A: 
def __init__(self): self.__x = 1 
class B(A): 
def display(self): 
print(self.__x) 
def main(): 
obj = B() 
obj.display() 
main() 

Private class members in the superclass can’t be accessed in the subclass.

  • Error, invalid syntax for object declaration
  • Error, private class member can’t be accessed in a subclass

25. What will be the output of the following Python code?

t[5]

The expression shown above results in a name error. This is because the name ‘t’ is not defined.

  • IndexError
  • NameError
  • TypeError
  • syntaticalError