Let's see what True and False are made of
>>> type(True)
<class 'bool'>
>>> type(False)
<class 'bool'>
>>> bool.__bases__
(<class 'int'>,)
True and False are bool
type which itself is a specialization of int
. And they behave like the integers 1 and 0.
>>> int(True)
1
>>> int(False)
0
But unlike regular variables, you can't assign anything to them. That's because they are also python language Keywords and the compiler won't allow the names "True" and "False" to be variables.
>>> True = 10
File "<stdin>", line 1
SyntaxError: cannot assign to True
>>>
In your examples, True
is 1
and False
is 0
, so
This... is the same as... resulting in...
1 == True 1 == 1 True
2 == False 2 == 1 False
3 == True 3 == 1 False
True + 10 1 + 10 11
False + 10 0 + 10 10