与__add__相反?

Jja*_*ang 1 python operator-overloading python-3.x

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

我知道__add__代表运营商+.

有哪些方法-,*,^,|&

Thi*_*ter 9

请参阅数据模型上的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)
Run Code Online (Sandbox Code Playgroud)

  • @Jjang:然后点击左侧的复选标记图标即可接受此答案. (5认同)