In python 3, I want to do operator overloading in a class I've made.
I know __add__
stands for operator +.
What are the methods for -
, *
, ^
, |
and &
?
In python 3, I want to do operator overloading in a class I've made.
I know __add__
stands for operator +.
What are the methods for -
, *
, ^
, |
and &
?
See the python docs on the data model.
The methods you asked about are: __sub__
, __mul__
, __xor__
, __or__
and __and__
Here's the full list:
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)