Python Operator Overloading Quiz
FREE Online Courses: Elevate Your Skills, Zero Cost Attached - Enroll Now!
Quiz Summary
0 of 10 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
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)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 10
1. Question
What type of methods are invoked by the operators?
CorrectIncorrect -
Question 2 of 10
2. Question
In Python, +, -, and, / are called ____.
CorrectIncorrect -
Question 3 of 10
3. Question
For what operands does the addition operator perform concatenation operation?
CorrectIncorrect -
Question 4 of 10
4. Question
What method is invoked by the addition operator?
CorrectIncorrect -
Question 5 of 10
5. Question
What operator invokes the __irshift__ method?
CorrectIncorrect -
Question 6 of 10
6. Question
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)
CorrectIncorrect -
Question 7 of 10
7. Question
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)
CorrectIncorrect -
Question 8 of 10
8. Question
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)
CorrectIncorrect -
Question 9 of 10
9. Question
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)
CorrectIncorrect -
Question 10 of 10
10. Question
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
CorrectIncorrect