Python bool() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in type

Definition

In Python, bool(x) returns True or False by testing the truthiness of x, the same test an if statement uses. bool() with no argument is False.

Falsy values are None, False, zero of any numeric type (0, 0.0, 0j), and empty containers ("", [], (), {}, set(), range(0)). Almost everything else is truthy. bool is a subclass of int, so True behaves like 1 in arithmetic.

bool is a built-in type (a class) that you call like a function: each call creates a new bool object. Like every built-in, it lives in the builtins module and is always available without an import.

Syntax

Pass any object; you always get one of two values.

python
flag = bool(value)
CallWhat it does
bool(0)Returns False.
bool("0")Returns True: a non-empty string.
bool([])Returns False: an empty list.
bool(None)Returns False.

In conditions you rarely need bool(): write if items: rather than if bool(items): or if len(items) > 0:.

Library declarations
python
bool(x=False, /)
# class bool(int): only two instances, True and False

Parameters

ParameterDescription
xOptional. Any object. Default False.

Return Value

Return ValueDescription
boolTrue if the object is truthy, otherwise False.

Python Examples

Example 1 — Truthy and Falsy Values Side by Side

Print the truth value of eleven common values in one aligned table.

python
values = [0, 1, -3, 0.0, "", "0", " ", [], [0], None, {}]

for v in values:
    print(f"{v!r:>6} -> {bool(v)}")

How It Works

  1. Only zero is falsy. Any non-zero number, positive or negative, is True; 0 and 0.0 are False.
  2. Strings by length. "" is falsy, but "0" and " " contain a character, so they are truthy.
  3. Containers by emptiness. [] and {} are falsy; [0] has one item, so it is truthy.
  4. Aligned output. !r:>6 right-aligns each value's repr in 6 characters to make the table readable.

Example 2 — Booleans Are Integers

Use True and False as numbers and see the string trap.

python
print(isinstance(True, int))
print(True + True)
print(sum([True, False, True]))
print(bool("False"))
print(int(True), str(False))

answers = ["yes", "", "no", ""]
filled = [a for a in answers if a]
print(len(filled), "of", len(answers), "answered")

How It Works

  1. Subclass of int. isinstance(True, int) is True, and True + True is 2.
  2. Counting. Summing booleans counts how many are True.
  3. The string trap. bool("False") is True: only the empty string is falsy.
  4. Filtering. if a keeps only non-empty answers, so 2 of the 4 are counted.

Example 3 — Custom Truthiness with __bool__ and __len__

Make two classes answer bool(): one through its length, one through an explicit rule.

python
class Basket:
    def __init__(self, items):
        self.items = list(items)

    def __len__(self):
        return len(self.items)


class Account:
    def __init__(self, balance):
        self.balance = balance

    def __bool__(self):
        return self.balance > 0


print(bool(Basket([])), bool(Basket(["apple"])))
print(bool(Account(0)), bool(Account(25)))

if not Basket([]):
    print("The basket is empty")

How It Works

  1. __len__ fallback. Basket has no __bool__, so Python uses its length: 0 items is falsy.
  2. __bool__ wins. Account defines its own rule: only a positive balance is truthy.
  3. Same test as if. if not Basket([]) runs the exact check that bool() performs.
  4. Default is truthy. A class with neither method would make every instance True.

Frequently Asked Questions

None, False, numeric zeros (0, 0.0, 0j), and empty containers such as "", [], (), {}, set(), and range(0). Everything else is truthy unless its class says otherwise.
Any non-empty string is truthy. To parse text, compare it: text.strip().lower() in ("true", "yes", "1").
Yes. True equals 1 and False equals 0, so sum() can count True values. You cannot subclass bool itself.
No, write if x:. The if statement already applies the same truth test.
Define __bool__(self) returning True or False. If you only define __len__, an instance is falsy when its length is 0.

Next: breakpoint()

Pause in the debugger (Python 3.7+).

breakpoint() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful