Python 3 reference · Built-in Functions

Python bool() Function

Convert a value to True or False using Python's truth rules: zero, empty and None are False, everything else is True.

Python 3 Since 3.0

Syntax

bool(x=False)

Parameters

ParameterDescription
x optional Any value. Default: False

Return value

True or False.

Examples

Truthy and falsy valuesTry it yourself
print(bool(0), bool(42))
print(bool(""), bool("hi"))
print(bool([]), bool([0]))
print(bool(None))

Output

False True
False True
False True
False
A classic surpriseTry it yourself
print(bool("False"))  # a non-empty string is True!
print("False".lower() == "true")

Output

True
False
bool is an intTry it yourself
print(True + True)  # bool is a subclass of int
print(isinstance(True, int))

Output

2
True

Common mistakes

  • bool("False") and bool("0") are True: any non-empty string is truthy. Compare the text instead.
  • You rarely need bool() in conditions: if items: already tests truthiness.

Version history

VersionChange
Python 3.0Added
Python 3.7x became a positional-only parameter.