python mathematical operators

Solutions on MaxInterview for python mathematical operators by the best coders in the world

showing results for - "python mathematical operators"
Iker
29 Jan 2020
1#PYTHON MATHEMATICAL OPERATORS
2OPERATOR	DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
3+	        Addition	        a + b   add(a, b)       __add__(self, other)
4–	        Subtraction	        a - b   sub(a, b)       __sub__(self, other)
5*	        Multiplication	    a * b   mul(a, b)       __mul__(self, other)
6/	        True Division	    a / b   truediv(a, b)   __truediv__(self, other)
7//	        Floor Division	    a // b  floordiv(a, b)  __floordiv__(self, other)
8%	        Modulo	            a % b   mod(a, b)       __mod__(self, other)
9**	        Power	            a ** b  pow(a, b)       __pow__(self, other)
10
11#PYTHON RELATIONAL OPERATORS
12OPERATOR    DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
13>	        Greater than	    a > b   gt(a, b)        __gt__(self, other)
14>=	        Greater or equal to	a >= b  ge(a, b)        __ge__(self, other)
15<	        Less than	        a < b   lt(a, b)        __lt__(self, other)
16<=	        Less or equal to	a <= b  le(a, b)        __le__(self, other)
17==	        Equal to	        a == b  eq(a, b)        __eq__(self, other)
18!=	        Not equal to        a != b  ne(a, b)        __ne__(self, other)
19
20#PYTHON BITWISE OPERATORS
21OPERATOR	DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
22&	        Bitwise AND	        a & b   and_(a, b)      __and__(self, other)
23|	        Bitwise OR	        a | b   or_(a,b)        __or__(self, other)
24^	        Bitwise XOR	        a ^ b   xor(a, b)       __xor__(self, other)
25~           Bitwise NOT         ~ a     invert(a)       __invert__(self)
26>>          Bitwise R shift     a >> b  rshift(a, b)    __irshift__(self, other)
27<<          Bitwise L shift     a << b  lshift(a, b)    __lshift__(self, other)