Comparison Operators
Comparison Operators in Python are used to compare two values and check whether a condition is True or False.
Real-Life Example
Comparison operators are like asking questions:
- Is 10 greater than 5? → True
- Is 8 equal to 10? → False
Just like answering Yes/No, Python gives True/False.

Explanation
These operators help in decision-making in programs.
They:
- Compare values like numbers or variables
- Return Boolean results (True/False)
- Are used in
ifstatements, loops, and logical conditions
Types of Comparison Operators
- == (Equal to) → Checks if two values are equal
- != (Not equal to) → Checks if values are different
- > (Greater than) → Checks if left value is greater
- < (Less than) → Checks if left value is smaller
- >= (Greater than or equal to)
- <= (Less than or equal to)
Example 1
x = 10
y = 20
print(x > y)
print(x == y)
Output:
False
False
Example 2
a = 15
b = 10
print("Is a greater than b?", a > b)
print("Is a equal to b?", a == b)
print("Is a not equal to b?", a != b)
Output:
Is a greater than b? True
Is a equal to b? False
Is a not equal to b? True
Explanation
a > b→ checks if a is greater than ba == b→ checks if both values are equala != b→ checks if values are different
Common Beginner Mistakes
- Using = instead of ==
- Confusing != and ==
- Not understanding True/False
- Wrong comparison logic
Key Points
- Comparison operators return True or False
- Used in decision-making (if conditions)
- Important for logical thinking in Python
- Helps in building program flow and control
Tips
- Practice comparing numbers and variables
- Use them in simple if programs
- Understand each symbol clearly
- Start with easy examples