Here are the operators in Python, explained in a simple and clear way:
🔹 Operators in Python
Operators are symbols used to perform operations on variables and values.
Python has 7 main types of operators:
1. Arithmetic Operators
Used for mathematical operations.
| Operator | Meaning | Example |
|---|---|---|
+ |
Addition | a + b |
- |
Subtraction | a - b |
* |
Multiplication | a * b |
/ |
Division | a / b |
% |
Modulus (remainder) | a % b |
** |
Exponent (power) | a ** b |
// |
Floor division | a // b |
2. Comparison (Relational) Operators
Used to compare values. Returns True/False.
| Operator | Meaning | Example |
|---|---|---|
== |
Equal to | a == b |
!= |
Not equal to | a != b |
> |
Greater than | a > b |
< |
Less than | a < b |
>= |
Greater than or equal | a >= b |
<= |
Less than or equal | a <= b |
3. Assignment Operators
Used to assign values to variables.
| Operator | Meaning | Example |
|---|---|---|
= |
Assign | x = 5 |
+= |
Add & assign | x += 3 → x = x+3 |
-= |
Subtract & assign | x -= 2 |
*= |
Multiply & assign | x *= 4 |
/= |
Divide & assign | x /= 2 |
%= |
Modulus & assign | x %= 2 |
**= |
Power & assign | x **= 3 |
//= |
Floor divide & assign | x //= 2 |
4. Logical Operators
Used for logical decisions.
| Operator | Meaning | Example |
|---|---|---|
and |
True if both are true | a > 5 and b < 10 |
or |
True if at least one is true | a > 5 or b < 10 |
not |
Reverses truth value | not(a > 5) |
5. Bitwise Operators
Works with binary numbers.
| Operator | Meaning |
|---|---|
& |
AND |
| ` | ` |
^ |
XOR |
~ |
NOT |
<< |
Left shift |
>> |
Right shift |
6. Membership Operators
Check membership in sequences (list, string, tuple).
| Operator | Meaning | Example |
|---|---|---|
in |
True if value exists | 'a' in 'apple' |
not in |
True if not exists | 3 not in [1,2,4] |
7. Identity Operators
Check if two objects are the same in memory.
| Operator | Meaning | Example |
|---|---|---|
is |
True if same object | a is b |
is not |
True if not same | a is not b |
✅ If you want, I can also provide:
✔ Examples of each operator
✔ Practice questions
✔ A PDF summary
✔ A comparison table
Would you like that?

0 Comments