If you want to check that every item in a list or other iterable passes a test in Python, the Python all() function is what you need. It takes one iterable and gives you back True only when every item is truthy.
Type this into a new Python file in your editor and run it:
print(all([3, 7, 12]), all([3, 0, 12]))
# True False
In this tutorial, I’ll show you conditions, dictionaries, ZIP codes and early stopping, all run on Python 3.12.5.
Python all() Syntax
all() takes exactly one argument. Type it in your Python file:
all(iterable, /)
| Parameter | Required | Default | Description |
|---|---|---|---|
| iterable | Yes | – | A list, tuple, set, dict, string or generator (positional-only) |
Return value: True when every item is truthy or the iterable is empty, otherwise False. Truthy follows the rules of the Python bool() function.
When to Use all() in Python
- Checking that every amount is positive
- Validating required form fields
- Testing each character of a string
- Replacing a loop with a flag variable
An empty list passes, so check if a list is empty first when that matters.
Example 1: Check if All Values in a List Are True
Let me start with a list of daily sales. To run it:
- Paste the code into any editor.
- Save it as
all_basic.pyin a folder. - In Command Prompt, go to that folder, type
python all_basic.pyand press Enter.
daily_sales = [1250, 980, 1675, 720]
print(all(daily_sales))
daily_sales.append(0)
print(all(daily_sales))
print(all([]))
Output:
True
False
True

How does this work? Every number was non-zero, so you get True. Adding 0 made it False, and the empty list printed True.
Example 2: Check a Condition for Every Item with all()
Usually you pass a condition. Save this as all_orders.py and run it in Command Prompt:
orders = {"#5101": 129.99, "#5102": 54.50, "#5103": -12.00, "#5104": 89.00}
print(all(amount > 0 for amount in orders.values()))
print(all(amount < 500 for amount in orders.values()))
Output:
False
True

How does this work? The -12.00 refund failed amount > 0, so you get False. Every amount was under 500.
Pro Tip: Skip the square brackets of a list comprehension so all() can stop early.
Example 3: Check Required Keys in a Python Dictionary
Here I validate a signup. Save this as all_required.py and run it in Command Prompt:
signup = {"name": "Liam Carter", "email": "", "state": "OH"}
print(all(key in signup for key in ("name", "email", "state")))
print(all(signup.values()))
Output:
True
False

How does this work? All three keys exist, but the empty email made all(signup.values()) False.
Example 4: Validate a US ZIP Code with all()
all() works on each character of a string. Save this as all_zipcodes.py and run it in Command Prompt:
zip_codes = ["10001", "73301", "9021O", "60614"]
for code in zip_codes:
valid = len(code) == 5 and all(ch.isdigit() for ch in code)
print(code, valid)
Output:
10001 True
73301 True
9021O False
60614 True

How does this work? “9021O” ends with the letter O, which fails the isdigit() method. For case, check if a string is all uppercase.
Example 5: See How all() Stops at the First False
A print shows which items all() reads. Save this as all_early.py and run it in Command Prompt:
def is_paid(invoice):
print("checking", invoice[0])
return invoice[1]
invoices = [("INV-1101", True), ("INV-1102", False), ("INV-1103", True)]
print(all(is_paid(inv) for inv in invoices))
Output:
checking INV-1101
checking INV-1102
False
How does this work? all() stopped at INV-1102 and never checked INV-1103. It short-circuits like and in logical operators in Python.
all() vs any() in Python
| Function | Returns True when | Empty iterable |
|---|---|---|
| all() | Every item is truthy | True |
| any() | At least one item is truthy | False |
For “at least one” rules, use the Python any() function.
Common Mistakes with Python all()
Save this as all_mistakes.py and run it in Command Prompt:
print(all({"open": 0}), all("000"), all([]))
for args in [(1, 2, 3), (5,)]:
try:
all(*args)
except TypeError as err:
print("TypeError:", err)
Output:
True True True
TypeError: all() takes exactly one argument (3 given)
TypeError: 'int' object is not iterable

- On a dict, all() checks keys. Use
.values(). - “000” is True: its characters aren’t empty.
- An empty list returns True.
- Pass one iterable, not separate values or a number.
Wrapping Up the Python all() Function
The Python all() function returns True when every item passes and False at the first one that fails. Pair it with a condition for readable rules.
Practice it inside a Python for loop, then browse more Python built-in functions and methods.
What People Ask About Python all() Function
Why does all() return True for an empty list?
all([]) returned True because no item fails.
What type does all() return?
Always bool, never the item itself.
Does all() treat None as False?
Yes. all([None]) returned False.
How do I check that all elements in a list are equal?
Compare each to the first: all(p == prices[0] for p in prices) returned True for three $19.99 prices.
Does all() work on a set?
Yes, any iterable works. all({0, 5}) returned False because 0 is falsy. See all() in the Python docs.
More Python posts on checking values:
- Python isinstance() and issubclass()
- lambda functions in Python
- isalpha() in Python
- one-line for loop in Python

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn