osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why do integers compare equal to booleans?


On 2018-11-16, Steve Keller <keller at no.invalid> wrote:
> Why do the integers 0 and 1 compare equal to the boolean values False
> and True and all other integers to neither of them?

Because Python used not to have a boolean type and used the integers
0 and 1 instead, so when the boolean type was introduced True and
False were made to behave very much like 1 and 0 for backwards
compatibility reasons.