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!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)