Operators
in Python
VAISHNAVI PANDEY
Arithmetic operators
Operator Operation Example
+ Addition 5+2=7
- Subtraction 4-2=2
* Multiplication 2*3=6
/ Division 4/2=2
% Modulo 5%2=1
** Power 4 ** 2 =16
VAISHNAVI PANDEY
Assignment Operators
Operator Name Example
= Assignment Operator a=7
+= Addition Assignment a += 1 # a = a + 1
-= Subtraction Assignment a -= 3 # a = a - 3
*= Multiplication Assignment a *= 4 # a = a * 4
/= Division Assignment a /= 3 # a = a / 3
%= Remainder Assignment a %= 10 # a = a % 10
**= Exponent Assignment a **= 10 # a = a **10
VAISHNAVI PANDEY
Comparison Operators
Operator Meaning Example
== Is Equal To 3 == 5 gives us False
!= Not Equal To 3 != 5 gives us True
> Greater Than 3 > 5 gives us False
< Less Than 3 < 5 gives us True
>= Greater Than or Equal To 3 >= 5 give us False
<= Less Than or Equal To 3 <= 5 gives us True
VAISHNAVI PANDEY
Logical Operators
Operator Example Meaning
and a and b Logical AND:
True only if both the operands are True
or a or b Logical OR:
True if at least one of the operands is True
not not a Logical NOT:
True if the operand is False and vice-versa.
VAISHNAVI PANDEY
Bitwise Operators
Operator Meaning Example
& Bitwise AND x & y = 0 (0000 0000)
| Bitwise OR x | y = 14 (0000 1110)
~ Bitwise NOT ~x = -11 (1111 0101)
^ Bitwise XOR x ^ y = 14 (0000 1110)
>> Bitwise right shift x >> 2 = 2 (0000 0010)
<< Bitwise left shift x << 2 = 40 (00101000).
VAISHNAVI PANDEY
Special Operators
Operator Meaning Example
is True if the operands are identical
(refer to the same object) x is True
is not True if the operands are not identical
(do not refer to the same object) x is not True
VAISHNAVI PANDEY
like
comment
share