Python 3 では、作成したクラスで演算子のオーバーロードを実行したいと考えています。
__add__
私は演算子 + の略を知っています。
-
、*
、^
、|
およびのメソッドは何&
ですか?
Python 3 では、作成したクラスで演算子のオーバーロードを実行したいと考えています。
__add__
私は演算子 + の略を知っています。
-
、*
、^
、|
およびのメソッドは何&
ですか?
データモデルに関するPythonドキュメントを参照してください。
あなたが尋ねた方法は次のとおりです:__sub__
、、、および__mul__
__xor__
__or__
__and__
完全なリストは次のとおりです。
object.__add__(self, other)
object.__sub__(self, other)
object.__mul__(self, other)
object.__truediv__(self, other)
object.__floordiv__(self, other)
object.__mod__(self, other)
object.__divmod__(self, other)
object.__pow__(self, other[, modulo])
object.__lshift__(self, other)
object.__rshift__(self, other)
object.__and__(self, other)
object.__xor__(self, other)
object.__or__(self, other)