Python provides operators to perform calculations, comparisons, and logical decisions in programs. Operators are essential because they allow Python to process data and make decisions.
In this post, we will learn Python operators in detail with examples.
🧠 What are Operators in Python?
Operators are special symbols used to perform operations on variables and values.
👉 In simple words:
- Operators = tools for calculations and logic
⚡ Types of Python Operators
Python supports several types of operators:
🔢 1. Arithmetic Operators
Used for mathematical calculations.
| Operator | Meaning | Example |
|---|---|---|
| + | Addition | a + b |
| - | Subtraction | a - b |
| * | Multiplication | a * b |
| / | Division | a / b |
| % | Modulus | a % b |
| ** | Exponent | a ** b |
| // | Floor Division | a // b |
🧪 Example:
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a % b)
print(a ** b)
print(a // b)
⚖️ 2. Comparison Operators
Used to compare values.
| Operator | Meaning |
|---|---|
| == | Equal |
| != | Not equal |
| > | Greater than |
| < | Less than |
| >= | Greater or equal |
| <= | Less or equal |
🧪 Example:
x = 10
y = 20
print(x == y)
print(x != y)
print(x > y)
print(x < y)
🔁 3. Logical Operators
Used to combine conditions.
| Operator | Meaning |
|---|---|
| and | Both true |
| or | One true |
| not | Reverse result |
🧪 Example:
a = True
b = False
print(a and b)
print(a or b)
print(not a)
📦 4. Assignment Operators
Used to assign values.
| Operator | Example |
|---|---|
| = | x = 10 |
| += | x += 5 |
| -= | x -= 5 |
| *= | x *= 5 |
| /= | x /= 5 |
🧪 Example:
x = 10
x += 5
print(x)
🔍 5. Identity Operators
Used to compare memory locations.
| Operator | Meaning |
|---|---|
| is | Same object |
| is not | Different object |
🧪 Example:
x = [1,2,3]
y = x
print(x is y)
📚 6. Membership Operators
Used to check if a value exists in a sequence.
| Operator | Meaning |
|---|---|
| in | Exists |
| not in | Does not exist |
🧪 Example:
fruits = ["apple", "banana"]
print("apple" in fruits)
print("mango" not in fruits)
🔢 7. Bitwise Operators
Used to perform binary operations.
| Operator | Meaning |
|---|---|
| & | AND |
| ^ | XOR |
| ~ | NOT |
| << | Left shift |
| >> | Right shift |
🧪 Example:
a = 5
b = 3
print(a & b)
print(a | b)
⚖️ Python Operators Summary
| Type | Purpose |
|---|---|
| Arithmetic | Math calculations |
| Comparison | Compare values |
| Logical | Combine conditions |
| Assignment | Assign values |
| Identity | Memory comparison |
| Membership | Check presence |
| Bitwise | Binary operations |
🚀 Why Operators are Important?
Operators are used in:
- Calculations ➗
- Decision making 🧠
- Data processing 📊
- Loops and conditions 🔁
- Real-world applications 🌐
🧾 Conclusion
Python operators are essential tools that allow you to perform calculations, compare values, and build logic in programs.
💡 Final Thought
If you master operators, you can build strong logic and solve real programming problems easily.


0 Comments