请稍候,加载中....

类的特殊方法(五)

这一组方法模拟数字运算

__add__方法

obj.__add__(self, other)

x + y 相当于x.__add__(y)

__sub__方法

obj.__sub__(self, other)

x - y 相当于 x.__sub__(y)

 

object.__mul__(self, other) object.__matmul__(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)


Python学习手册-