与__add__相反?

时间:2012-04-21 15:59:16

标签: python python-3.x operator-overloading

在python 3中,我想在我创建的类中进行运算符重载。

我知道__add__代表运营商+。

-*^|&有哪些方法?

1 个答案:

答案 0 :(得分:9)

请参阅the python docs on the data model

您询问的方法有:__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)