## 3.3.8 Emulating numeric types 

The following methods can be defined to emulate numeric objects. Methods corresponding to operations that are not supported by the particular kind of number implemented (e.g., bitwise operations for non-integral numbers) should be left undefined. 

object. __add__ ( self , other$_{)}$ object. __sub__ ( self , other ) object. __mul__ ( self , other ) object. __matmul__ ( 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$_{)}$ 

These methods are called to implement the binary arithmetic operations ($_{+}$ ,$_{-}$ ,$_{*}$ ,$_{@}$ ,$_{/}$ ,$_{//}$ ,$_{%}$ ,$_{divmod()}$ , pow() ,$_{**}$ ,$_{<<}$ ,$_{>>}$ ,$_{&}$ ,$_{^}$ ,$_{|}$ ). For instance, to evaluate the expression$_{x + y}$ , where x is an instance of a class that has an$_{__add__()}$ method,$_{x.__add__(y)}$ is called. The$_{__divmod__()}$ method should be the equivalent to using$_{__floordiv__()}$ and$_{__mod__()}$ ; it should not be related to$_{__truediv__()}$ . Note that$_{__pow__()}$ should be defined to accept an optional third argument if the ternary version of the built-in$_{pow()}$ function is to be supported. 

If one of those methods does not support the operation with the supplied arguments, it should return NotImplemented . 

object. __radd__ ( self , other$_{)}$ object. __rsub__ ( self , other$_{)}$ object. __rmul__ ( self , other$_{)}$ object. __rmatmul__ ( self , other$_{)}$ object. __rtruediv__ ( self , other$_{)}$ object. __rfloordiv__ ( self , other$_{)}$ object. __rmod__ ( self , other$_{)}$ object. __rdivmod__ ( self , other$_{)}$ object. __rpow__ ( self , other [, modulo ] ) object. __rlshift__ ( self , other$_{)}$ object. __rrshift__ ( self , other$_{)}$ object. __rand__ ( self , other$_{)}$ object. __rxor__ ( self , other$_{)}$ object. __ror__ ( self , other$_{)}$ 

These methods are called to implement the binary arithmetic operations ($_{+}$ ,$_{-}$ ,$_{*}$ ,$_{@}$ ,$_{/}$ ,$_{//}$ ,$_{%}$ ,$_{divmod()}$ , pow() ,$_{**}$ ,$_{<<}$ ,$_{>>}$ ,$_{&}$ ,$_{^}$ ,$_{|}$ ) with reflected (swapped) operands. These functions are only called if the left operand does not support the corresponding operation 3 and the operands are of different types. 4 For instance, to evaluate the expression$_{x - y}$ , where y is an instance of a class that has an$_{__rsub__()}$ method,$_{y.}$ __rsub__(x) is called if$_{x.__sub__(y)}$ returns NotImplemented . 

Note that ternary$_{pow()}$ will not try calling$_{__rpow__()}$ (the coercion rules would become too compli- cated). 

Note: If the right operand’s type is a subclass of the left operand’s type and that subclass provides a different implementation of the reflected method for the operation, this method will be called before the left operand’s 

