In this we are going to see a basic example of assignment operation using operator overloading in Python Programming Language.
class Point:
def __init__(self, X):
self.X = X
def __iadd__(self, U):
self.X += U.X
return self
def __str__(self):
return "({})".format(self.X)
p1 = Point(int(input("Please enter the value: ")))
p2 = Point(int(input("Please enter the value: ")))
p1 += p2
print("Assigning p2 to p1 gives us =",p1)
# Coded by Dhiraj Shelke
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP