-2
>>> 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?

shx2
  • 61,779
  • 13
  • 130
  • 153
Arindam Roychowdhury
  • 5,927
  • 5
  • 55
  • 63

1 Answers1

3

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.

shx2
  • 61,779
  • 13
  • 130
  • 153