Skip to main content

bool()

The bool() function in Python is a built-in function that returns the boolean value of a specified object. It evaluates the truth value of an object, returning True if the object is true and False if the object is false. Objects that are considered false include empty objects like empty strings, lists, tuples, and dictionaries, as well as numerical values of zero. Other objects are considered true.

Parameter Values

Parameter Description
x

The parameter that will be converted to a Boolean. It can be an expression, a value, or a variable.

Return Values

The bool() function in Python can only return True or False.

How to Use bool() in Python

Example 1:

Returns the boolean value of an expression. If the expression is empty, it returns False.

bool(10 > 5)
Example 2:

If the input is 0, None, empty container, empty string, or False, it returns False; otherwise, returns True.

bool([])
Example 3:

Non-empty containers, non-zero numbers, and non-empty strings return True.

bool('hello')