git add example
This commit is contained in:
parent
c94859813f
commit
34e28754fd
24
python-temel/class.add.py
Normal file
24
python-temel/class.add.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user