June 2017
Beginner
352 pages
8h 39m
English
We can also compare the order of quantities using the rich comparison operators. Use < to determine if the first argument is less than the second:
>>> g < 30True
Likewise, use > to determine if the first is greater than the second:
>>> g > 30False
You can test less-than or equal-to with <=:
>>> g <= 20True
We can use the greater-than or equal-to with >= ,shown as follows:
>>> g >= 20True
If you have experience with relational operators from other languages, then Python's operators are probably not surprising at all. Just remember that these operators are comparing equivalence, not identity, a distinction we'll cover in detail in coming chapters.
Read now
Unlock full access