Use two or more relational operators in one sentence in python

有些话、适合烂在心里 提交于 2019-11-29 12:28:29

Python supports double-ended comparisons. For example,

3 < x <= 7

is a check for 3 < x and x <= 7 (with x being evaluated just once).

By extension,

5 < 5 <= 3 > 10

means (5 < 5) and (5 <= 3) and (3 > 10), all of which are False, so the whole expression evaluates to False.

https://docs.python.org/2/reference/expressions.html#comparisons

It's evaluated in order, so your expression expands to

5 < 5 and 5 <= 3 and 3 > 10

which evaluates to False

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!