overloading 1

This commit is contained in:
Mert Gör 🇹🇷 2023-07-27 22:50:56 +03:00
parent a10503c12d
commit 103edfb801
No known key found for this signature in database
GPG key ID: 2100A876D55B39B9

View file

@ -0,0 +1,28 @@
class Number:
def __init__(self, number):
self.number = number
def disp(self):
print(self.number)
def __add__(self, x):
return Number(self.number + x.number)
def __sub__(self, x):
return Number(self.number - x.number)
def __mul__(self, x):
return Number(self.number * x.number)
def __truediv__(self, x):
return Number(self.number / x.number)
def __str__(self):
return str(self.number)
x = Number(10)
y = Number(20)
z = Number(2)
k = x + y * z
print(k)