Sub-Type of Int
We'll cover the following
Bool as a sub-type of int
Bool is actually a subtype of int. This means that boolean values of True
and False
can be considered as specialized integer values. Therefore, True
is equivalent to the integer 1
and False
is equivalent to the integer 0
.
For instance, Python will evaluate the following expression as True
.
print(True == 1)
However, although the values are considered equal, the identity in terms of object type is not the same. The identity operator (e.g., is) can be employed to check whether or not two objects are the same in terms of identity.
In the example below, True is 1
evaluates to False
. So even if True
and 1
have the same value, they are distinct objects with different identities.
print(True is 1)
The following expression is evaluated as False
.