>>> True + 2
3
>>> False + 2
2
I can understand that somehow, True means 1 and False means 0 . So does it mean, a Boolean and integer operation always gives an integer?
>>> True + 2
3
>>> False + 2
2
I can understand that somehow, True means 1 and False means 0 . So does it mean, a Boolean and integer operation always gives an integer?
In python bool
is a subclass of int
, and therefor satisfies the "is-a" relation, meaning a bool is-a int.
To demonstrate:
issubclass(bool, int)
=> True
isinstance(True, int)
=> True
In practice this means that in any operation which works on an int, the int can be substituted with a bool.