In answer to your second part:
It's true that all non-zero integers are "Truthy" but this does not mean that 5 == True
will return True
. The ==
operator is comparing value and, when comparing values, 5 is not equal to True
. If you compare bool(5) == True
then that will return True
. When you do if 5:
what you actually are doing is if bool(5):
.
The reason that 1 == True
returns True
is that in Python the boolean
class is a subclass of int
, with True
being represented by 1
and False
being represented by 0
. So 1 == True
returns True because they are equal.
Note that, as discussed in this question, this is NOT GUARANTEED in Python 2.x as True
and False
can be re-defined. In Python 3.x they are keywords which will always be equal to 1 and 0, respectively.