transformation

all()

Returns True if every element of the iterable is truthy (or if the iterable is empty). Short-circuits on the first falsy value.

all(iterable)

Parameters

Parameter Purpose
iterable Iterable of values tested for truthiness
returns True if every element truthy; True for an empty iterable (vacuous)

Examples

all([1, 2, 3])

Returns True

all([1, 0, 3])

Returns False (0 is falsy)

all([])

Returns True (vacuous truth)

all(isinstance(x, int) for x in [1, 2, 3])

Returns True

Gotcha

all([]) returns True (vacuous truth) — a common source of bugs when the collection was expected to be non-empty.

Related built-ins

← All Python built-ins