2

Unlike most of the programming languages in python, I see boolean type to be a place holder of an integer value 1, as the following code works perfectly.

>>> i = 0
>>> while i < 10:
...     i += True
...     print i

I wonder, Why would the designer of python create boolean types, when they have no explicit work which can't be done by integer, further more it behaves like an integer, and can be used as one, so other than readability is there any other significance of having a boolean in python ?

Andrew Hewitt
  • 518
  • 4
  • 14
anand
  • 1,506
  • 14
  • 28
  • @BhargavRao Its a different from that, I am asking it from language design perspective that, is there any other need of it other than readability ? – anand Sep 23 '16 at 06:37
  • NVM, poke's found a better target – Bhargav Rao Sep 23 '16 at 06:39
  • 1
    @anand The primary reason behind it is likely backwards compatibility. And then, once that was no longer a real problem, there isn’t any reason to actually change it to become independent. bool being a subtype of int has no drawbacks. – poke Sep 23 '16 at 06:40

0 Answers0