Python operator overloading: The arithmetic magic methods

Python operator overloading: The arithmetic magic methods

Just as + in Python invokes __add__, other operators invoke other magic methods:

• – is __sub__
• * is __mul__
• / is __truediv__
• // is __floordiv__
• % is __mod__
• ** is __pow__

Your methods can do whatever you want. But do try to stick to conventional expectations.