Python Operators
📘 Python
👁 74 views
📅 Nov 05, 2025
⏱ Estimated reading time: 2 min
Python Operators
Python operators are special symbols used to perform operations on variables and values. They are classified into several types.
1. Arithmetic Operators
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 5 - 3 | 2 |
* | Multiplication | 5 * 3 | 15 |
/ | Division | 5 / 2 | 2.5 |
// | Floor Division | 5 // 2 | 2 |
% | Modulus | 5 % 2 | 1 |
** | Exponentiation | 2 ** 3 | 8 |
2. Assignment Operators
| Operator | Description | Example |
|---|---|---|
= | Assign value | x = 5 |
+= | Add and assign | x += 3 → x = x + 3 |
-= | Subtract and assign | x -= 2 → x = x - 2 |
*= | Multiply and assign | x *= 3 → x = x * 3 |
/= | Divide and assign | x /= 2 → x = x / 2 |
//= | Floor divide and assign | x //= 2 |
%= | Modulus and assign | x %= 3 |
**= | Exponent and assign | x **= 2 |
3. Comparison Operators
| Operator | Description | Example | Result |
|---|---|---|---|
== | Equal to | 5 == 5 | True |
!= | Not equal to | 5 != 3 | True |
> | Greater than | 5 > 3 | True |
< | Less than | 5 < 3> | False |
>= | Greater than or equal | 5 >= 5 | True |
<= | Less than or equal | 5 <= 3 | False |
4. Logical Operators
| Operator | Description | Example | Result |
|---|---|---|---|
and | Returns True if both are True | True and False | False |
or | Returns True if any is True | True or False | True |
not | Returns inverse | not True | False |
5. Bitwise Operators
| Operator | Description | Example | Result |
|---|---|---|---|
& | AND | 5 & 3 | 1 |
| ` | ` | OR | `5 |
^ | XOR | 5 ^ 3 | 6 |
~ | NOT | ~5 | -6 |
<< | Left shift | 5 << 1> | 10 |
>> | Right shift | 5 >> 1 | 2 |
6. Membership Operators
| Operator | Description | Example | Result |
|---|---|---|---|
in | Returns True if value exists | 'a' in 'Python' | False |
not in | Returns True if value does not exist | 'a' not in 'Python' | True |
7. Identity Operators
| Operator | Description | Example | Result |
|---|---|---|---|
is | Returns True if both are the same object | x is y | Depends |
is not | Returns True if both are not the same object | x is not y | Depends |
8. Key Points
-
Arithmetic operators handle math calculations.
-
Assignment operators update variable values.
-
Comparison operators are used in conditions.
-
Logical operators combine boolean expressions.
-
Bitwise operators work on binary values.
-
Membership and identity operators check existence and object identity.
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials