Special methods
II – arithmetic methods
>>> class A:
...
def __init__(self, value):
...
self.data = value
...
def __add__(self, other):
...
return A(self.data+other.data)
...
>>> a = A(5)+A(7)
>>> a.data
12
>>> b = A(3).__add__(A(2))
>>> b.data
5