Comparison Operators
- Comparison operators in Python are used to compare two values. They return True or False and are mainly used in conditions like if statements and loops to control program flow.
A comparison operator is a symbol used to compare two values. It returns True if the comparison is correct, otherwise False.
Examples: == (equal), != (not equal), > (greater than), < (less than), >= (greater or equal), <= (less or equal).
Comparison operators in Python are used to compare two values. The result of a comparison is always a Boolean value: True or False.
Comparison operators are very useful in decision-making, loops, and conditional statements in Python.
Comparison Operators Example
Demonstrates the use of all comparison operators with two numbers.
a = 10
b = 5
# Equal to
print("a == b:", a == b)
# Not equal to
print("a != b:", a != b)
# Greater than
print("a > b:", a > b)
# Less than
print("a < b:", a < b)
# Greater than or equal to
print("a >= b:", a >= b)
# Less than or equal to
print("a <= b:", a <= b)