Python any() Function With Examples

The Python any() function returns True when at least one item in an iterable is truthy, and False when none is, including when the iterable is empty. Pair it with a generator expression to ask “does anything here match?” in one line:

any(total > 500 for total in [89.50, 612.00, 45.25])   # True
any([])                                               # False

I ran every example on this page on Python 3.12.5 in Command Prompt, so the outputs are real.

In this tutorial, we’ll cover which values count as true, conditions with generators, why any() stops early, strings and dictionaries, and how it compares with all().

Which values make Python any() return True?

Python’s any() tests each item’s truth value. Zero, empty strings, None, False and empty containers are falsy; nearly everything else is truthy:

print(any([0, "", None, False]))   # every item is falsy
print(any([0, "", 3]))             # 3 is truthy
print(any([]))                     # empty -> False
print(any([[], {}, ()]))           # empty containers are falsy
print(any([[0]]))                  # a list holding 0 is not empty
print(any("0"))                    # the string "0" is truthy

Output:

False
True
False
False
True
True
Command Prompt output of Python any() on lists of falsy values, an empty list and the string 0
Only the lists holding a truthy item return True, and the empty list returns False.

Note the last two lines: [[0]] holds a non-empty list, and "0" is a non-empty string, so both count as true. The rules come from the Python bool() function, which any() applies to each item.

Check a condition across a list with any() and a generator

Most of the time you don’t have a list of booleans. You have records, and you want to know whether any of them passes a test. A generator expression builds those True/False answers one at a time:

orders = [
    {"id": "A-1001", "state": "TX", "total": 89.50,  "shipped": True},
    {"id": "A-1002", "state": "CA", "total": 612.00, "shipped": True},
    {"id": "A-1003", "state": "NY", "total": 45.25,  "shipped": False},
]

big = any(o["total"] > 500 for o in orders)
print("Any order over $500.00?", big)

late = any(not o["shipped"] for o in orders)
print("Any order not shipped?", late)

print("Any order from Florida?", any(o["state"] == "FL" for o in orders))

first = next((o["id"] for o in orders if o["total"] > 500), None)
print("First big order:", first)

Output:

Any order over $500.00? True
Any order not shipped? True
Any order from Florida? False
First big order: A-1002
Command Prompt output of Python any() with generator expressions checking order totals, shipping status and state
One order is over $500.00 and one isn’t shipped, so both checks print True; no order comes from Florida.

any() only says yes or no. When you need the matching item itself, next() with a default returns the first match, as the last line shows. For keeping every match instead, see filtering lists in Python.

Does Python any() stop at the first True value?

Yes. any() short-circuits: it stops reading as soon as it finds a truthy item. That only saves work when the items are produced lazily, though. Watch the print calls here:

def is_negative(n):
    print(f"  checking {n}")
    return n < 0

readings = [12, 7, -3, 40, 18]

print("generator:")
print(any(is_negative(n) for n in readings))

print("list comprehension:")
print(any([is_negative(n) for n in readings]))

Output:

generator:
  checking 12
  checking 7
  checking -3
True
list comprehension:
  checking 12
  checking 7
  checking -3
  checking 40
  checking 18
True
Command Prompt output showing Python any() stopping at -3 with a generator but checking all five readings with a list comprehension
The generator stops after checking -3; the square brackets check all five readings before any() even starts.

Square brackets build the whole list first, so every function call runs. I always drop the brackets and pass a generator. If you use list comprehensions in Python a lot, this is the one spot where the bracket-free version is clearly better.

Use Python any() with strings and dictionaries

A string is an iterable of characters, so any() handles character checks well. A dictionary iterates over its keys, which surprises a lot of people:

password = "Spring2026"
print("Has a digit:", any(ch.isdigit() for ch in password))
print("Has a symbol:", any(not ch.isalnum() for ch in password))

stock = {"apples": 0, "pears": 0, "plums": 4}
print("any(stock):         ", any(stock))            # checks the KEYS
print("any(stock.values()):", any(stock.values()))   # checks the counts

flags = {0: "off", "": "blank"}
print("any(flags):", any(flags))                      # both keys are falsy

Output:

Has a digit: True
Has a symbol: False
any(stock):          True
any(stock.values()): True
any(flags): False
Command Prompt output of Python any() checking a password for digits and symbols and testing dictionary keys versus values
any(stock) is True because the keys are non-empty strings, while stock.values() is True only because plums has 4.

For the counts, pass .values(). Character tests like isdigit() are covered in the isdigit() method in Python, and key lookups in checking if a Python dictionary contains a key.

Python any() vs all() and the or operator

any() is a chained or over an iterable, and all() is a chained and. The difference shows most on empty input:

ExpressionReturns True whenEmpty input
any(items)at least one item is truthyFalse
all(items)every item is truthyTrue
a or b or cone of a fixed set of values is truthyn/a

Use or for a few known values and any() when the count isn’t fixed. Testing that every item passes is covered in the Python all() function. When the question is really “is this empty?”, see checking if a variable is null or empty in Python.

A few related checks build on the same idea:

Frequently asked questions

What does any() return for an empty list?

False. With no items, nothing can be truthy.

What’s the difference between any() and all() in Python?

any() needs one truthy item; all() needs every item truthy and returns True for an empty iterable.

Does any() check dictionary keys or values?

Keys. Use any(d.values()) to test the values.

Is any() faster than a for loop?

It does the same early-exit work in C, so it’s usually as fast or faster and shorter to read.

How do I get the item that made any() return True?

Use next((x for x in items if test(x)), None), which returns the first match or None.

Where is any() documented?

See any() in the Python docs.