14

Just found out that in Python, bools are ints.

WTF

Comments
  • 8
    True == 1
    False == 0
    every object that doesnt overrides the __bool__ or the __eq__ method is usually True.
  • 3
    Its a feature since a very long time
  • 3
    okay, I officially hate this feature
  • 3
    Type coercion is debatable but most of the time pretty cool. isinstance(True, int) == True is just plain stupid
  • 8
    And this is why i always say that learning c as a first language will help a lot in the future
  • 0
    Yeah, but not languages follow 1 == True, for a good reason
  • 4
    It's quite reasonable I think. Allows for some Boolean sorcery like additions and multiplications

    Edit: don't do that tho. Your senior dev will murder you
  • 0
    @Excessive Keep in mind that most of the time that's highly implementation dependent
  • 3
    So .. does True + True = 2? xD
  • 1
    Lots of languages do this
  • 1
    @anolis Not even JavaScript does it this badly though
  • 0
    yup

    several langs use 0 and 1 internally as False and True, respective, so this isn't surprising.
Add Comment