0

Is there any reason why isinstance( False , numbers.Number ) gives the True result.

isinstance( False , numbers.Number)
>>>True
isinstance( True , numbers.Number)
>>>True

I have basic idea about boolean in computer language since 0 is False and 1 is True.

With my personal knowledge, python should have differences with this situations where Boolean is separated from int and float. Is there any (historical) reason why it is coded as True with such class?

胡亦朗
  • 397
  • 1
  • 3
  • 9
  • 2
    `bool` is a subclass of `int`; `True` and `False` have the numeric values `1` and `0`. You can read the specification for the `bool` type: [here](https://www.python.org/dev/peps/pep-0285/) – Patrick Haugh Jan 23 '18 at 02:30
  • 2
    See https://stackoverflow.com/questions/8169001/why-is-bool-a-subclass-of-int – jpp Jan 23 '18 at 02:31

1 Answers1

3

Early Python (before 2.2?) didn't have a separate boolean type: people used 0 and 1 instead. When the bool type was added, it was made a subclass of ints to simplify the use of existing code in new Pythons.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662