Boolean (bool) (Python)

A boolean in Python is a value that is either True or False. Booleans are produced by comparisons and conditions and drive if-statements and loops.

Python

In Python, True and False must be capitalized. Many values are 'truthy' or 'falsy' too — empty strings, empty lists, 0, and None act as False in a condition, while most other values act as True.

Examples

Python

is_open = True
print(5 > 3)
print(bool(""), bool("hi"))

Output:

True
False True

Learn it in a lesson

See also

Back to the Dictionary