Python all() Function Explained

Python’s all() function checks whether every item in an iterable is truthy.

It is a small function, but it causes a lot of beginner confusion because:

  • it works with truthy and falsy values
  • it takes one iterable argument
  • all([]) returns True, which often seems strange at first

Quick answer

numbers = [1, 2, 3]
result = all(numbers)
print(result)  # True

all() returns True only if every item in the iterable is truthy. If even one item is falsy, it returns False.

What all() does

all():

  • checks every item in an iterable
  • returns True if all items are truthy
  • returns False if any item is falsy
  • works with lists, tuples, sets, strings, and other iterables

Basic syntax:

all(iterable)

The argument must be a single iterable, not several separate values.

What truthy and falsy mean

In Python, values are often treated as either True or False in conditions.

  • Truthy values act like True
  • Falsy values act like False

Common falsy values include:

  • 0
  • 0.0
  • ''
  • None
  • False
  • []
  • {}
  • set()

Most other values are truthy.

If you are new to this idea, see Python booleans explained: true and false.

You can test this with bool():

values = [1, 0, '', 'hello', None]

print([bool(x) for x in values])

Output:

[True, False, False, True, False]

This matters because all() does not compare values. It checks whether each value is truthy.

Basic examples

Example: all numbers are non-zero

numbers = [1, 2, 3]
print(all(numbers))

Output:

True

Each number is truthy, so all() returns True.

Example: one number is zero

numbers = [1, 0, 3]
print(all(numbers))

Output:

False

The value 0 is falsy, so all() returns False.

Example: strings

words = ['apple', 'banana', 'cherry']
print(all(words))

Output:

True

All strings are non-empty, so they are truthy.

Now look at a list with an empty string:

words = ['apple', '', 'cherry']
print(all(words))

Output:

False

The empty string '' is falsy.

How all() works with conditions

all() is often used with a generator expression.

This is useful when you want to check whether every item matches a rule.

For example, to check whether all numbers are positive:

numbers = [1, 2, 3]
result = all(x > 0 for x in numbers)

print(result)

Output:

True

Here is one that fails:

numbers = [1, -2, 3]
result = all(x > 0 for x in numbers)

print(result)

Output:

False

The expression x > 0 is checked for each number. If every check is True, then all() returns True.

This pattern keeps code short and readable.

If you want more practice with this style, see how to use list comprehensions in Python and what is an iterable in Python.

Empty iterable behavior

all([]) returns True.

This surprises many beginners.

Example:

print(all([]))

Output:

True

Why?

Because there is no item in the iterable that fails the test.

Think of it this way:

  • all() returns False when it finds a falsy item
  • an empty iterable has no items at all
  • so there is nothing that makes it return False

This is normal Python behavior, even if it feels odd at first.

The same idea applies to other empty iterables too:

print(all(()))
print(all(''))

Output:

True
True

Common beginner mistakes

Passing multiple arguments

This is wrong:

# Wrong
# print(all(1, 2, 3))

all() does not take multiple separate values.

Use one iterable instead:

print(all([1, 2, 3]))

Assuming all() compares values automatically

Some beginners expect this:

numbers = [5, 5, 5]
print(all(numbers))

This does not check whether all values are equal.

It only checks whether all values are truthy. Since 5 is truthy, the result is:

True

If you want to check whether all values are equal, you need a condition:

numbers = [5, 5, 5]
print(all(x == 5 for x in numbers))

Forgetting that 0 and empty strings are falsy

print(all([1, 2, 0]))       # False
print(all(['a', 'b', '']))  # False

A single falsy value makes the whole result False.

Not understanding why all([]) is True

This is expected behavior:

print(all([]))  # True

It does not mean the list contains True. It means there is no item that fails the check.

Useful quick tests:

print(all([1, 2, 3]))
print(all([1, 0, 3]))
print([bool(x) for x in [1, 0, '', 'hello', None]])
print(all(x > 0 for x in [1, 2, 3]))
print(all([]))

When to use all()

all() is useful when you want to check that every item passes a simple test.

Common use cases:

  • check if every string in a list is non-empty
  • validate that all numbers meet a condition
  • make sure all values are valid before processing data

Example: check that every name is non-empty

names = ['Alice', 'Bob', 'Charlie']
print(all(names))

Output:

True

Example: check that every score is at least 50

scores = [75, 80, 50]
print(all(score >= 50 for score in scores))

Output:

True

If the logic becomes hard to read, a plain loop is often better for beginners.

For related tasks, see how to filter a list in Python and iterators and iterable objects explained.

FAQ

What does all() return in Python?

It returns True if every item in the iterable is truthy. It returns False if at least one item is falsy.

Why does all([]) return True?

Because there are no items in the iterable that fail the test.

Can all() take multiple values directly?

No. It takes one iterable argument, such as a list or tuple.

What is the difference between all() and any()?

all() needs every item to be truthy. any() needs at least one item to be truthy. See Python any() function explained.

See also