2017-09-10 10:05:31 -04:00
|
|
|
class A:
|
|
|
|
|
|
|
|
def __init__(self, v):
|
|
|
|
self.v = v
|
|
|
|
|
|
|
|
def __add__(self, o):
|
|
|
|
if isinstance(o, A):
|
|
|
|
return A(self.v + o.v)
|
|
|
|
return A(self.v + o)
|
|
|
|
|
|
|
|
def __radd__(self, o):
|
|
|
|
return A(self.v + o)
|
|
|
|
|
|
|
|
def __repr__(self):
|
2019-10-18 04:18:06 -04:00
|
|
|
return "A({})".format(self.v)
|
2017-09-10 10:05:31 -04:00
|
|
|
|
|
|
|
print(A(3) + 1)
|
|
|
|
print(2 + A(5))
|