Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Function

all

Returns True when every element in an iterable is truthy, and also for an empty iterable. It short-circuits at the first false element.

How it works

all consumes an iterable and tests the truth value of each element from left to right. It stops as soon as a false value appears, and returns True when no element is false, including when the iterable has no elements.

Syntax

all(iterable, /)

Parameters

NameTypeDescription
iterableiterableAn iterable whose elements are tested for truth.

Returns

True if every element of iterable is true, or if iterable is empty; otherwise False.

Key points

  • all returns True only when every value obtained from its iterable has a true Boolean value.
  • No elements also yields True, following universal-quantification semantics.
  • Processing ends immediately when an element is false, so unnecessary remaining values are not evaluated.

Common mistakes

  • An empty iterable produces True, so an empty validation set does not indicate that any item was checked.

Example: Validate every status

healthy = [200, 200, 204]
if all(status < 400 for status in healthy):
    print("all checks passed")

Checks each status lazily and prints only when every status is below 400.

When to use it

Aggregate validations

Validate a collection of predicates before proceeding.

Lazy checks

Check streamed or generated values without materializing them.

Guard execution

Confirm every status, permission, or feature flag meets a condition.

Interview questions

QWhat does all do?

all takes one iterable and returns True only when every element is truthy. It also returns True for an empty iterable.

Follow-up: What happens with a generator? all consumes it as it iterates, stopping when it encounters the first false value.

QWhich inputs can all accept?

all accepts any iterable, not only a list. A generator expression is useful when values can be produced lazily, because evaluation can stop early.

Follow-up: Why can this reduce work? Values after the first false element are never requested.

QHow is all conceptually implemented?

The documented equivalent loops over the iterable and immediately returns False when an element is false; after the loop, it returns True. This explains both short-circuiting and the empty-iterable result.

Follow-up: How would you require at least one item too? Check that the iterable is non-empty separately, because all alone treats emptiness as success.

  • any
  • bool
  • filter

Source: Built-in Functions. Checked 2026-10-16.