Imagine this "sneaky" python code:
>>> 1 == 2 < 3
False
According to Python documentation all of the operators in, not in, is, is not, <, <=, >, >=, !=, ==
have the same priority, but what happens here seems contradictory.
I get even weirder results after experimenting:
>>> (1 == 2) < 3
True
>>> 1 == (2 < 3)
True
What is going on?
(Note)
>>> True == 1
True
>>> True == 2
False
>>> False == 0
True
>>> False == -1
False
Boolean type is a subclass of int
and True represents 1
and False represents 0
.
This is likely an implementation detail and may differ from version to version, so I'm mostly interested in python 3.10.