Comparison Operators
Files associated with this lesson:
Comparison Operators.ipynb
Comparison Operators¶
Used to compare objects, they return a Booolean value to represent the result. Example 5 > 3
(five greater than three) returns True
.
We'll divide them in 3 categories:
- eq/neq: Equality.
- gt/gte: Greater than / greater than or equals to.
- lt/lte: Lower than / lower than or equals to.
eq/neq¶
In [1]:
print(4 == 4)
print(4 == 3)
print(4 != 4)
print(4 != 3)
Can be applied with any object. For example, with strings:
In [2]:
print('a' == 'a')
print('a' == 'A')
print('a' != 'A')
print('a' != 'a')
gt / gte¶
In [1]:
print(4 > 3)
print(4 > 4)
print(4 > 5)
In [2]:
print(4 >= 3)
print(4 >= 4)
print(4 >= 5)
lt / lte¶
In [4]:
print(4 < 5)
print(4 < 4)
print(4 < 3)
In [5]:
print(4 <= 5)
print(4 <= 4)
print(4 <= 3)
In [ ]: