Overview of Magic Methods
Binary Operators
Operator Method
- object.add(self, other)
- object.sub(self, other)
- object.mul(self, other)
// object.floordiv(self, other)
/ object.truediv(self, other)
% object.mod(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)
Extended Assignments
Operator Method
+= object.iadd(self, other)
-= object.isub(self, other)
*= object.imul(self, other)
/= object.idiv(self, other)
//= object.ifloordiv(self, other)
%= object.imod(self, other)
**= object.ipow(self, other[, modulo])
<<= object.ilshift(self, other)
= object.irshift(self, other)
&= object.iand(self, other)
^= object.ixor(self, other)
|= object.ior(self, other)
Unary Operators
Operator Method
- object.neg(self)
- object.pos(self)
abs() object.abs(self)
~ object.invert(self)
complex() object.complex(self)
int() object.int(self)
long() object.long(self)
float() object.float(self)
oct() object.oct(self)
hex() object.hex(self
Comparison Operators
Operator Method
< object.lt(self, other)
<= object.le(self, other)
== object.eq(self, other)
!= object.ne(self, other)
= object.ge(self, other)
object.gt(self, other)