Operator Overloading In Python: MCQs Python Programming

Operator Overloading In Python. Multiple Choice Questions on the topic of Operator Overloading in Python Programming. This set contains 10 Multiple Choice Questions.

 

Operator Overloading In Python

 

 

Which function overloads the // operator ??

a) __div__()
b) __ceildiv__()
c) __floordiv__()
d) __truediv__()

 

Which operator is overloaded by the __or__() function ??

a) ||
b) |
c) //
d) /

 

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

a) __add__(), __str__()
b) __str__(), __add__()
c) __sum__(), __str__()
d) __str__(), __sum__()

 

Which function overloads the >> operator ??

a) __more__()
b) __gt__()
c) __ge__()
d) none of the mentioned

 

Which operator is overloaded by __lg__() ??

a) <
b) >
c) !=
d) none of the mentioned

 

 

Operator Overloading In Python

 

 

Which function overloads the == operator ??

a) __eq__()
b) __equ__()
c) __isequal__()
d) none of the mentioned

 

Which operator is overloaded by __invert__() ??

a) !
b) ~
c) ^
d) –

 

Which function overloads the + operator ??

a) __add__()
b) __plus__()
c) __sum__()
d) none of the mentioned

 

Which of the following Python code will print True ??

a = foo(2)
b = foo(3)
print(a < b)

 

a) class foo:
def __init__(self, x):
self.x = x
def __lt__(self, other):
if self.x < other.x:
return False
else:
return True

 

b) class foo:
def __init__(self, x):
self.x = x
def __less__(self, other):
if self.x > other.x:
return False
else:
return True

 

c) class foo:
def __init__(self, x):
self.x = x
def __lt__(self, other):
if self.x < other.x:
return True
else:
return False

 

d) class foo:
def __init__(self, x):
self.x = x
def __less__(self, other):
if self.x < other.x:
return False
else:
return True

 

Which function is called when the following Python code is executed ??

f = foo()
format(f)

a) format()
b) __format__()
c) str()
d) __str__()

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!