Next / Previous / Contents / TCC Help System / NM Tech homepage

7.3. Type bool: Boolean truth values

A value of bool type represents a Boolean (true or false) value. There are only two values, written in Python as “True” and “False”.

Internally, True is represented as 1 and False as 0, and they can be used in numeric expressions as those values.

Here's an example. In Python, the expression “a < b” compares two values a and b, and returns True if a is less than b, False is a is greater than or equal to b.

>>> 2 < 3
True
>>> 3 < 2
False
>>> True+4
5
>>> False * False
0

These values are considered False wherever true/false values are expected, such as in an if statement:

All other values are considered True. To convert any value to a Boolean, see Section 20.5, “bool(): Convert to Boolean”.