Python Programming - Polymorphism - Discussion

Discussion Forum : Polymorphism - General Questions (Q.No. 40)
40.
Consider the following code:
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)
What concept is demonstrated in this code?
Operator overloading
Method overloading
Method overriding
Polymorphism
Answer: Option
Explanation:
This code demonstrates operator overloading using the __sub__() method to customize the behavior of the subtraction operator (-) for instances of the class.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.