Python Operator Overloading Quiz
Python Operator Overloading Quiz
by
PythonGeeks Team
Get Ready for Your Dream Job: Click, Learn, Succeed, Start Now!
0 of 10 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
You must sign in or sign up to start the quiz.
You must first complete the following:
Quiz complete. Results are being recorded.
0 of 10 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0 )
Earned Point(s): 0 of 0 , (0 )
0 Essay(s) Pending (Possible Point(s): 0 )
Show Question
1
Show Question
2
Show Question
3
Show Question
4
Show Question
5
Show Question
6
Show Question
7
Show Question
8
Show Question
9
Show Question
10
Review / Skip
Answered
Correct
Incorrect
Question 1 of 10
What type of methods are invoked by the operators?
Question 2 of 10
In Python, +, -, and, / are called ____.
Question 3 of 10
For what operands does the addition operator perform concatenation operation?
Question 4 of 10
What method is invoked by the addition operator?
Question 5 of 10
What operator invokes the __irshift__ method?
Question 6 of 10
What is the output of the below code?
Code
>>> class Multiply:
>>> def __init__(self, x):
>>> self.x = x
>>> def __mul__(self, other):
>>> return f”{self.x} X {other.x} = {self.x * other.x}”
>>> a = Multiply(5)
>>> b = Multiply(10)
>>> print(a * b)
Question 7 of 10
What is the output of the below code?
Code
>>> class Class1:
>>> def __init__(self, n):
>>> self.n = n
>>> def __add__(self, other):
>>> return self.n – other.n
>>> a = Class1(4)
>>> b = Class1(1)
>>> print(a + b)
Question 8 of 10
What is the output of the below code?
Code
>>> class Car:
>>> def __init__(self, speed):
>>> self.speed = speed
>>> def __gt__(self, other):
>>> if self.speed > other.speed:
>>> return “Car1 is faster than Car2”
>>> else:
>>> return “Car2 is faster than Car1”
>>> car1 = Car(130)
>>> car2 = Car(250)
>>> print(car1 > car2)
Question 9 of 10
What is the output of the below code?
Code
>>> class Words:
>>> def __init__(self, str):
>>> self.str = str
>>> def __truediv__(self, other):
>>> return len(self.str) / len(other.str)
>>> word1 = Words(“Hello Worlds”)
>>> word2 = Words(“Python”)
>>> print(word1 / word2)
Question 10 of 10
Choose the correct missing line to complete the code.
Code
>>> class Hello:
>>> def __iadd__(self, other):
>>> return “Adding”
>>> a = Hello()
>>> # Missing Line
>>> print(a)
Output
Adding
We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google | Facebook
PythonGeeks Team
At PythonGeeks, our team provides comprehensive guides on Python programming, AI, Data Science, and machine learning. We are passionate about simplifying Python for coders of all levels, offering career-focused resources.