Answers for "Operators in python"

21

python operators

#PYTHON RELATIONAL OPERATORS
OPERATOR    DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
>	        Greater than	    a > b   gt(a, b)        __gt__(self, other)
>=	        Greater or equal to	a >= b  ge(a, b)        __ge__(self, other)
<	        Less than	        a < b   lt(a, b)        __lt__(self, other)
<=	        Less or equal to	a <= b  le(a, b)        __le__(self, other)
==	        Equal to	        a == b  eq(a, b)        __eq__(self, other)
!=	        Not equal to        a != b  ne(a, b)        __ne__(self, other)

#PYTHON MATHEMATICAL OPERATORS
OPERATOR	DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
+	        Addition	        a + b   add(a, b)       __add__(self, other)
–	        Subtraction	        a - b   sub(a, b)       __sub__(self, other)
*	        Multiplication	    a * b   mul(a, b)       __mul__(self, other)
/	        True Division	    a / b   truediv(a, b)   __truediv__(self, other)
//	        Floor Division	    a // b  floordiv(a, b)  __floordiv__(self, other)
%	        Modulo	            a % b   mod(a, b)       __mod__(self, other)
**	        Power	            a ** b  pow(a, b)       __pow__(self, other)

#PYTHON BITWISE OPERATORS
OPERATOR	DESCRIPTION	        SYNTAX  FUNCTION        IN-PLACE METHOD
&	        Bitwise AND	        a & b   and_(a, b)      __and__(self, other)
|	        Bitwise OR	        a | b   or_(a,b)        __or__(self, other)
^	        Bitwise XOR	        a ^ b   xor(a, b)       __xor__(self, other)
~           Bitwise NOT         ~ a     invert(a)       __invert__(self)
>>          Bitwise R shift     a >> b  rshift(a, b)    __irshift__(self, other)
<<          Bitwise L shift     a << b  lshift(a, b)    __lshift__(self, other)
Posted by: Guest on April-19-2021
5

python math operators

# Below follow the math operators that can be used in python
# ** Exponent	
2 ** 3 # Output: 8
# % Modulus/Remaider	
22 % 8 # Output: 6
# // Integer division	
22 // 8 # Output: 2
# / Division	
22 / 8 # Output: 2.75
# * Multiplication	
3 * 3 # Output: 9
# - Subtraction	
5 - 2 # Output: 3
# + Addition	
2 + 2 # Output: 4
Posted by: Guest on February-21-2020
2

python exponent operator

#python exponent operator
num = 2
new_num = num**2
#answer would be 4
Posted by: Guest on April-24-2020
5

|= operator python

>>> s1 = {"a", "b", "c"}
>>> s2 = {"d", "e", "f"}

>>> # OR, | 
>>> s1 | s2
{'a', 'b', 'c', 'd', 'e', 'f'}
>>> s1                                                     # `s1` is unchanged
{'a', 'b', 'c'}

>>> # In-place OR, |=
>>> s1 |= s2
>>> s1                                                     # `s1` is reassigned
{'a', 'b', 'c', 'd', 'e', 'f'}
Posted by: Guest on March-02-2021
5

python logical operators

not 
and 
or
Posted by: Guest on November-01-2020
0

Operators in python

x = 5
y = 6

d = 12 % 5     # d is 2
z = x + y      # z is 11
w = x - y      # w is -1
q = 5 * 6      # q is 30
u = 10 / x     # u is 2.0
p = 10 * 2.0   # p is 20.0
t = x ** 3     # t is 125
c = 28 // y    # c is 5
Posted by: Guest on October-17-2021

Python Answers by Framework

Browse Popular Code Answers by Language