For some reason
999 < (0, 6, 7, 8)
Evaluates to True
In fact, all tuples appear to be greater than all ints.
According to the docs ,
Instances of
tuple
orlist
can be compared only within each of their types.
Is there documentation for this behaviour? Is there some implicit casting happening?
According to the documentation you linked, when it discusses comparing tuples to other types:
ordering comparison across these types gives an arbitrary order.
So, it sounds like this behavior is undefined in Python 2 (correct me if I'm wrong). Doing this same comparison in Python 3 gives the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
print(999 < (0, 6, 7, 8))
TypeError: '<' not supported between instances of 'int' and 'tuple'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.