Python 3 reference · Built-in Functions

Python all() Function

Return True if every item in an iterable is truthy, or if the iterable is empty. Stops at the first falsy item.

Python 3 Since 3.0

Syntax

all(iterable)

Parameters

ParameterDescription
iterable Any iterable: a list, tuple, set, generator, …

Return value

True if all items are truthy (or there are no items), otherwise False.

Examples

Basic useTry it yourself
print(all([True, 1, "yes"]))
print(all([True, 0, "yes"]))
print(all([]))  # empty: nothing is false

Output

True
False
True
Check a condition for every itemTry it yourself
scores = [72, 88, 95, 61]
print(all(s >= 60 for s in scores))  # did everyone pass?
print(all(s >= 70 for s in scores))

Output

True
False
Combine several checksTry it yourself
password = "Secret123"
checks = [len(password) >= 8, any(c.isdigit() for c in password), any(c.isupper() for c in password)]
print("strong" if all(checks) else "weak")

Output

strong

Common mistakes

  • all([]) is True. If an empty list should count as a failure, check if items and all(...).
  • Pass a generator expression (all(x > 0 for x in nums)) rather than a list comprehension, so all() can stop as soon as it finds a false item.

Version history

VersionChange
Python 3.0Added