Python
Comparison Operators in Python
Comparison Operators
64
#description
Comparison operators are used in Python to compare values and return Boolean values (True or False) depending on whether the comparison is true or not.
The following are the comparison operators in Python:
- Equal to operator (==): This operator compares two values and returns True if they are equal, and False otherwise.
- Not Equal to operator (!=): This operator compares two values and returns True if they are not equal, and False otherwise.
- Greater than operator (>): This operator compares two values and returns True if the first value is greater than the second value, and False otherwise.
- Less than operator (<): This operator compares two values and returns True if the first value is less than the second value, and False otherwise.
- Greater than or equal to operator (>=): This operator compares two values and returns True if the first value is greater than or equal to the second value, and False otherwise.
- Less than or equal to operator (<=): This operator compares two values and returns True if the first value is less than or equal to the second value, and False otherwise.
Here are some examples of using comparison operators in Python:
a = 5
b = 10
print(a == b) # False
print(a != b) # True
print(a > b) # False
print(a < b) # True
print(a >= b) # False
print(a <= b) # True
We use these operators frequently in conditional statements like if, elif or while loops.
March 25, 2023