Comparison

Table of Contents

Comparison by Types discussion

>>> a = ['0', 9999, {}, [], False, ()]
>>> a.sort()
>>> a
[False, 9999, {}, [], '0', ()]

CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don't support proper comparison are ordered by their address.

Compare three values howto

x == y == z
x == y and y == z  # 'y' is evaluated twice

# ok
0 < x < 10
10 >= z >= 2