+ 4
Why False is an instance of integer?
Here is the code: print(False in (0, 1)) print(isinstance(False, int)) outputs: True True https://code.sololearn.com/c9NlnwDTw75k/?ref=app
8 Answers
+ 3
Usually in programming, True is symbolized by the number 1 and False is symbolized by the number 0.
+ 2
Exactly.
Here, because boolean is a subclass of int. So, False is 0. Then isinstance(False, int) == isinstance(0, int).
Check: issubclass(bool, int) in #Python documentations.
+ 2
Thank you. Exactly.
+ 2
Originally, python had no boolean type, so 0 and 1 where used as False and True
When they finally introduced boolens they needed to make them an instance of int for retro-compatibility
As for today, there really isn't any need for it, so it's there just for an historic reason
+ 1
Because it's one bit of one byte so it's either 1 or zero this is how integers are saved just with more bytes
0
Thank you.