1. 程式人生 > >Python:Python運算子過載(簡版)

Python:Python運算子過載(簡版)

__add__(self, other): +
__sub__(self, other): -
__mul__(self, other): *
__matmul__(self, other): @
__truediv__(self, other): /
__floordiv__(self, other): //
__mod__(self, other): %
__divmod__(self, other): divmod, divmod(a, b) = (a/b, a%b)
__pow__(self, other[,modulo]): **, pow()
__lshift__(self, other): <<
__rshift__(self, other): >>
__and__(self, other): &
__xor__(self, other): ^
__or__(self, other): |