Usage of the “==” operator for three objects

Usage of the “==” operator for three objects,第1张

Usage of the “==” operator for three objects

Python has chained comparisons, so these two forms are equivalent:

x == y == zx == y and y == z

except that in the first, y is only evaluated once.

This means you can also write:

0 < x < 1010 >= z >= 2

etc. You can also write confusing things like:

a < b == c is d   # Don't  do this

Beginners sometimes get tripped up on this:

a < 100 is True   # Definitely don't do this!

which will always be false since it is the same as:

a < 100 and 100 is True   # Now we see the violence inherent in the system!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5668053.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存