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