Built-in Functions and Types

bool()

Convert a value into a Boolean using Python truth testing. Empty containers, None and numeric zero are false in ordinary use; a nonempty string such as "False" is true. Custom objects can control testing with __bool__() or __len__(). bool is an int subclass with only two instances and cannot itself be subclassed.

Formal Syntax & Structure

python syntaxpython
bool(object=False, /)

Parameters & Attributes

NameTypeDescription
objectobjectValue to test; omitting it produces False.

Return Value

bool

True for a truthy value, False otherwise.

Working Example

Example Snippetpython
cart = ["notebook"]print(bool(cart))print(bool("False"))print(bool([]))
Python Reference