
上QQ阅读APP看书,第一时间看更新
Rich comparison operators
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 < 30
True
Likewise, use > to determine if the first is greater than the second:
>>> g > 30
False
You can test less-than or equal-to with <=:
>>> g <= 20
True
We can use the greater-than or equal-to with >= ,shown as follows:
>>> g >= 20
True
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.