Is python bool sorting defined?

Is the True and False ordering well-defined in Python, or is it left as an implementation detail?

From the console, I see False sorting to True ... but I don't know what I should rely on or not.

(I'm sure there are some Python docs about this, but I can't find it ...)

+6
source share
1 answer

http://docs.python.org/2/reference/datamodel.html#the-standard-type-hierarchy

Logical . They represent true values ​​False and True. Two objects representing the values ​​False and True are the only Boolean objects. The Boolean type is a subtype of prime integers, and logical values ​​behave like values ​​0 and 1, respectively, in almost all contexts, with the exception that when converting to a string, the string "False" or "True" is returned, respectively.

This tells me that python requires False < True , False == 0 , True == 1 , True != 2 .

The same wording is preserved in Python 3 .

+12
source

All Articles