git add example

This commit is contained in:
Mert Gör 🇹🇷 2023-08-03 19:07:59 +03:00
parent c94859813f
commit 34e28754fd
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9

24
python-temel/class.add.py Normal file
View File

@ -0,0 +1,24 @@
class Number:
def __init__(self, val):
self.val = val
def __add__(self, x):
return Number(self.val + x.val)
def __iadd__(self, x):
return Number(self.val + x.val + 1)
def __repr__(self):
return str(self.val)
a = Number(10)
b = Number(20)
a = a + b
print(a)
a = Number(10)
b = Number(20)
a += b
print(a)