Used for basic mathematical operations.
Operator | Description | Example | Result |
---|---|---|---|
+ |
Addition | 2 + 3 |
5 |
- |
Subtraction | 5 - 2 |
3 |
* |
Multiplication | 3 * 4 |
12 |
/ |
Division (float) | 10 / 3 |
3.33 |
// |
Floor Division | 10 // 3 |
3 |
% |
Modulus (remainder) | 10 % 3 |
1 |
** |
Exponentiation | 2 ** 3 |
8 |
Compare two values and return True
or False
.
Operator | Description | Example | Result |
---|---|---|---|
== |
Equal to | 5 == 5 |
True |
!= |
Not equal to | 5 != 3 |
True |
> |
Greater than | 5 > 3 |
True |
< |
Less than | 3 < 5 |
True |
>= |
Greater or equal | 5 >= 5 |
True |
<= |
Less or equal | 3 <= 5 |
True |
Used to assign values to variables.
Operator | Description | Example |
---|---|---|
= |
Assign | x = 10 |
+= |
Add and assign | x += 2 |
-= |
Subtract and assign | x -= 1 |
*= |
Multiply and assign | x *= 5 |
/= |
Divide and assign | x /= 3 |
//= |
Floor divide and assign | x //= 2 |
%= |
Modulus and assign | x %= 4 |
**= |
Exponent and assign | x **= 2 |
Used to combine conditional statements.
Operator | Description | Example | Result |
---|---|---|---|
and |
True if both are true | x > 5 and x < 10 |
True |
or |
True if one is true | x > 5 or x == 2 |
True |
not |
Reverse the result | not(x > 5) |
False |
Used to perform bit-level operations.
Operator | Description | Example |
---|---|---|
& |
AND | 5 & 3 → 1 |
` | ` | OR |
^ |
XOR | 5 ^ 3 → 6 |
~ |
NOT | ~5 → -6 |
<< |
Left Shift | 5 << 1 → 10 |
>> |
Right Shift | 5 >> 1 → 2 |
Used to test whether a value exists in a sequence (like list, tuple, string).
Operator | Description | Example | Result |
---|---|---|---|
in |
True if present | 'a' in 'apple' |
True |
not in |
True if not present | 'x' not in 'apple' |
True |
Compare memory locations of objects.
Operator | Description | Example | Result | |||||
---|---|---|---|---|---|---|---|---|
is | Same object? | x is y |
True |
|||||
is not | Not same object? | x is not y |
True |