Booleans and Relational Operators

Conditional execution requires that the conditions being checked evaluate to either true or false. A special data type in Python called bool creates only two objects of this type, True, and False. Every relational operation (>, ==, in, etc) evaluates to this one of these values. Every object evaluated as an expression in an if or elif statement is converted to a True or False (it just happens that relational expressions already evaluate to them!)

Booleans

In [10]:
# Our Boolean data type in Python
bool
Out[10]:
bool
In [11]:
type(False)
Out[11]:
bool
In [3]:
type(True)
Out[3]:
bool

Relational Expressions

Relational expressions can be standalone expressions, they are not required to only appear in if or elif statements. For example:

In [4]:
num = 20
In [5]:
4 > num
Out[5]:
False
In [6]:
res = 4 > num
In [7]:
print(res)
False