Operators
Arithmetic
+ # Addition
- # Subtraction
* # Multiplication
/ # Division
% # Modulus
** # Exponent
// # Floor Division
Floor Division: The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (e.g.: 5//2 = 2, -5//2 = -3)
Assignment
= # Assign
+= # Add and assign
-= # Subtract and assign
*= # Multiply and assign
/= # Divide and assign
%= # Modulus and assign
//= # Divide(floor) and assign
**= # Exponent and assign
&= # Bitwise AND and assign
|= # Bitwise OR and assign
^= # Bitwise XOR and assign
>>= # Bitwise right shift and assign
<<= # Bitwise left shift and assign
Bitwise
Bitwise operator works on bits and performs bit by bit operation
& # AND
| # OR
^ # XOR
~ # Invert all the bits
# a = 0011 1100
# ~a = 1100 0011
<< # Left shift
>> # Right shift
Identity
Identity operators compare the memory locations of two objects.
is # True if both variables are the same object
is not # True if both variables are not the same object
Logical
and # True if both statements are true
or # True if one of the statements is true
not # Reverse the result, returns False if the result is true
Membership
Python’s membership operators test for membership in a sequence, such as strings, lists, or tuples.
in # True if a sequence with the specified value is present in the object
not in # True if a sequence with the specified value is not present in the object
Relational / Comparison
== # Equal
!= # Not equal
<> # Removed in Python 3
> # Greater than
< # Less than
>= # Greater than or equal
<= # Less than or equal