特殊メソッド.四則演算に対応
Python
__add__() 等のメソッドを実装する
+:__add__-:__sub__*:__mul__/:__div__
をそれぞれ実装すればいい
例
py
def __add__(self, other):
self.x += other.x
return self.x
__add__() 等のメソッドを実装する
+ : __add__- : __sub__* : __mul__/ : __div__をそれぞれ実装すればいい
例
def __add__(self, other):
self.x += other.x
return self.x