0

How comparison operators(< and >) work between two lists? After compare there is always single bool return True/False, but do they compare each element or at least one element should be greater/lesser or what? :O

Example : Let's assume i have two lists

>>> a = [1, 2, 3]
>>> b = [3, 4, 5]

When i use > greater than/lesser than < i have this results :

>>> a > b
False
>>> a < b
True

It looks intuitive, because every element in b is greater than same index element in a. Now I'll do it with slightly modified b list.

>>> a = [1, 2, 3]
>>> b = [3, 0, 0]
>>> a > b
False
>>> a < b
True

Only first b element is bigger than first a element, so why a<b is still True?

s.paszko
  • 633
  • 1
  • 7
  • 21

0 Answers0