Hacker News new | past | comments | ask | show | jobs | submit login

Python was created February 1991, but it didn't have a boolean type until 2002 per PEP 285 <https://www.python.org/dev/peps/pep-0285/>

The rationale for making bool a subset of integers is for ease of implementation and substitutability (which aids backwards compatibility)47, as explained here:

> In an ideal world, bool might be better implemented as a separate integer type that knows how to perform mixed-mode arithmetic. However, inheriting bool from int eases the implementation enormously (in part since all C code that calls PyInt_Check() will continue to work -- this returns true for subclasses of int). Also, I believe this is right in terms of substitutability: code that requires an int can be fed a bool and it will behave the same as 0 or 1.

I have some Python code where there are still a number of uses of 0 and 1 for false and true, because it was written before Python added a boolean type.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: