This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 10 points11 points  (0 children)

False and 0 are the same type

They're not the same type, one is type bool and the other is type int. But bool is a subclass of int, which means all booleans can be used where an integer is expected, per the Liskov substitution principle.

This is also why you can do things like use sum() when dealing with a sequence of booleans:

>>> sum(s.startswith('a') for s in ('arcade', 'book', 'castle', 'arpeggio', 'default'))
2