|
|
|
|
|
by slurgfest
4872 days ago
|
|
True and False are not 1 and 0 in Python. >>> (1 is True) or (True is 1)
False
>>> (0 is False) or (False is 0)
False
>>> isinstance(0, bool) or isinstance(1, bool)
False
>>> isinstance(False, bool) and isinstance(True, bool)
True
Indexing with boolean expressions is bad style to begin with, but if you are going to do it then a bool cast shows explicitly what you are trying to do. |
|
>>> isinstance(True, int)
True
>>> bool.__mro__
(<type 'bool'>, <type 'int'>, <type 'object'>)
Although they aren't literally the same object, 1 == True does evaluate to True.