3 ms·
Python goes even further beyond. >>> True + True 2 >>> True * 13 + (1 - False) * 17 30
by qsort 4y ago
Python goes even further beyond.
>>> True + True
2
>>> True * 13 + (1 - False) * 17
30
- tech2 4y agoThat's history coming back to bite it though. There was a period where the symbols True and False existed in Python but the bool class did not. True was _literally_ 1, and False was 0. Because of this, for backward compat, bool is a subclass of int.
- kgwgk 4y agoWhat you show there is that int(True) is one and int(False) is zero. (The same happens in R, for what it's worth. as.integer(TRUE) is one and as.integer(FALSE) is zero and the operations you wrote work just he same.)