Name

__add__, __div__, __floordiv__, __mod__, __mul__, __sub__,__truediv__

Synopsis

__add__(self,other)
__div__(self,other)
__floordiv__(self,other)
__mod__(self,other)
__mul__(self,other)
__sub__(self,other)
__truediv__(self,other)
                     

Operators x + y, x / y, x // y, x % y, x * y, x - y, and x/y, respectively, call these methods. The operator / calls __truediv__, if present, instead of __div__, in the situations where division is non-truncating, as covered in Section 4.5.2.

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.