Python all() Function

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

Definition

In Python, all(iterable) returns True if every item is truthy, and False as soon as it finds one falsy item. An empty iterable gives True, because there is no item that fails.

It is usually paired with a generator expression, such as all(score >= 60 for score in scores). It short-circuits: it stops at the first failure and does not evaluate the rest. Its partner any() checks whether at least one item is truthy.

all() is a built-in function: it lives in the builtins module, so it is always available without an import.

Syntax

Pass an iterable, usually a generator expression.

python
ok = all(iterable)
ok = all(condition(x) for x in items)
CallWhat it does
all([1, 2, 3])Returns True.
all([1, 0, 3])Returns False.
all([])Returns True (nothing fails).
all(x > 0 for x in xs)Are all numbers positive?

all() always returns a real True or False, not the item itself.

Library declarations
python
all(iterable, /)

Parameters

ParameterDescription
iterableRequired. Any iterable; each item is tested for truthiness.

Return Value

Return ValueDescription
boolTrue if no item is falsy, otherwise False.

Python Examples

Example 1 — How all() Treats Truthy and Falsy Items

Check several lists, including an empty one.

python
print(all([True, 1, "yes"]))
print(all([True, 0, "yes"]))
print(all([]))
print(all(["a", "b", ""]))

How It Works

  1. Every item truthy. True, 1, and "yes" are all truthy, so the result is True.
  2. One zero is enough. 0 is falsy, so the second list fails.
  3. Empty is True. No item fails, so all([]) is True.
  4. Empty string. The final "" is falsy and makes the last check False.

Example 2 — Validate Scores and Passwords

Use generator expressions and a list of named checks to validate data.

python
scores = [72, 88, 95, 60]
print(all(s >= 60 for s in scores))
print(all(0 <= s <= 100 for s in scores))

passwords = ["Secret12", "hunter2", "Pa55word"]
for pw in passwords:
    checks = [
        len(pw) >= 8,
        any(c.isdigit() for c in pw),
        any(c.isupper() for c in pw),
    ]
    print(pw, all(checks))

How It Works

  1. Rule over a list. Every score is at least 60, so the first check passes.
  2. Range check. Chained comparisons test both bounds for each score.
  3. Several rules. Each password builds a list of three booleans; all() needs every one to be True.
  4. Too short. "hunter2" has only 7 characters and no capital letter, so it fails.

Example 3 — all() Stops at the First Failure

Print inside the test to see which items are actually checked, and nest two calls for a matrix.

python
def check(n):
    print("checking", n)
    return n > 0


print(all(check(n) for n in [3, -1, 5]))
print(all(check(n) for n in []))

matrix = [[1, 2], [3, 4]]
print(all(all(x > 0 for x in row) for row in matrix))

How It Works

  1. Early exit. After -1 fails, all() returns False and 5 is never checked.
  2. Empty, no calls. With no items, check() never runs and the answer is True.
  3. Nested all(). The inner call checks one row; the outer call requires every row to pass.
  4. Generator required. The laziness works because the argument is a generator expression, not a list.

Frequently Asked Questions

all() is True when no item is falsy. An empty iterable has no falsy items, so the answer is True (this is called vacuous truth).
all() needs every item to be truthy; any() needs at least one.
Yes. It returns False at the first falsy item and does not look at the rest.
all(x == items[0] for x in items), or len(set(items)) <= 1 for hashable items.
No, it always returns True or False. Use next() with a generator to find the first failing item.

Next: anext()

Await the next item of an async iterator (Python 3.10+).

anext() →

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.

9 people found this page helpful