bool()

bool(x=False)
Returns: bool · Updated March 13, 2026 · Built-in Functions
built-in type-conversion boolean

The bool() function converts a value to a boolean — either True or False. It’s Python’s way of checking truthiness, and understanding what values are “falsy” versus “truthy” is fundamental to writing clean, idiomatic code.

Syntax

bool(x=False)

Parameters

ParameterTypeDefaultDescription
xanyFalseThe value to convert to a boolean

Examples

Basic conversion

print(bool(True))    # True
print(bool(False))   # False
print(bool(1))       # True
print(bool(0))       # False

String and collection conversion

print(bool("hello")) # True
print(bool(""))      # False
print(bool([1, 2]))  # True
print(bool([]))      # False
print(bool({"a": 1})) # True
print(bool({}))      # False

None conversion

print(bool(None))    # False

Truthy and Falsy Values

Python treats certain values as implicitly False. These are called “falsy”:

  • False
  • None
  • 0, 0.0, 0j, Decimal(0), Fraction(0, 1)
  • '' (empty string)
  • [], (), {} (empty collections)
  • Objects with __len__() returning 0

Everything else is “truthy”:

# Practical example: using bool implicitly in conditionals
user = {"name": "Alice", "email": None}

if user.get("email"):  # bool(None) is False
    print(f"Sending email to {user['email']}")
else:
    print("No email address")

# Using bool directly
is_active = bool(user.get("subscriptions"))

Common Patterns

Default arguments

def process(data=None):
    data = data or []  # Converts None to empty list
    # Equivalent to: data = [] if data is None else data

Filtering falsy values

values = [0, 1, "", "hello", None, [], [1, 2]]
truthy = [v for v in values if v]  # [1, 'hello', [1, 2]]
falsy = [v for v in values if not v]  # [0, '', None, []]

Boolean coercion in conditionals

result = bool(some_function_returning_value())
if result:
    print("Success")

Errors

bool() itself rarely raises errors. However, custom classes can define __bool__() to control their boolean value:

class Empty:
    def __bool__(self):
        return False

print(bool(Empty()))  # False

If __bool__() is not defined but __len__() is, __len__() is used as a fallback:

class ShortList:
    def __len__(self):
        return 0

print(bool(ShortList()))  # False

See Also