Clarification when comparing objects of different types

The following suggestions cause confusion for me (from a Guido tutorial on python.org):

"Note that comparing objects with different types is legal. The outcome is deterministic but arbitrary: the types are ordered by their name. Thus, the list is always smaller than the string, the string is always smaller than the tuple, etc." than the tuple and etc. "

This means that for:

a=[90]
b=(1)
a<b

The result should be True. But this is not so! Can you help me here than motorcade etc. "

Also, what is meant by “Result is deterministic but arbitrary”?

0
source share
2 answers

(1) int. , (1,), tuple.

+6

, . , .

>>> set([1]) > [1]
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: can only compare to a set

, py3k:

>>> [1,2] > (3,4)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: unorderable types: list() > tuple()
>>> [1,2] > "1,2"
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: unorderable types: list() > str()
+3

Source: https://habr.com/ru/post/1540874/


All Articles