Python any() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in

Definition

In Python, any(iterable) returns True as soon as it finds one truthy item, and False if none is truthy. An empty iterable gives False, because nothing was found.

Pair it with a generator expression to ask “does anything match?”: any(word.startswith("x") for word in words). It short-circuits on the first match. not any(...) means “none match”, and all() is its counterpart for “every item matches”.

any() is a built-in function: it lives in the builtins module, so it is always available without an import.

Syntax

Pass an iterable, usually a generator expression.

python
found = any(iterable)
found = any(condition(x) for x in items)
CallWhat it does
any([0, 0, 1])Returns True.
any([0, "", None])Returns False.
any([])Returns False.
any(x < 0 for x in xs)Is there a negative number?

For a simple membership test of one value, value in items is clearer than any(x == value for x in items).

Library declarations
python
any(iterable, /)

Parameters

ParameterDescription
iterableRequired. Any iterable; each item is tested for truthiness.

Return Value

Return ValueDescription
boolTrue if at least one item is truthy, otherwise False.

Python Examples

Example 1 — How any() Treats Falsy Items

Check lists of falsy values, a list with one truthy value, an empty list, and a string.

python
print(any([False, 0, "", None]))
print(any([0, 0, 7]))
print(any([]))
print(any("abc"))

How It Works

  1. All falsy. False, 0, "", and None give False.
  2. One is enough. 7 is truthy, so the second list returns True.
  3. Empty is False. There is nothing truthy in an empty list.
  4. Strings are iterables. Each character is a non-empty string, so "abc" gives True.

Example 3 — any() Stops at the First Match

Print inside the test to see the early exit, and use not any() to find words without vowels.

python
def is_negative(n):
    print("testing", n)
    return n < 0


print(any(is_negative(n) for n in [4, -2, -9]))
print(any(is_negative(n) for n in []))

words = ["tree", "sky", "rhythm"]
print([w for w in words if not any(c in "aeiou" for c in w)])

How It Works

  1. Early exit. -2 is the first negative number, so -9 is never tested.
  2. Empty, no calls. Without items, the function never runs and the answer is False.
  3. None match. not any(...) is true when no character is a vowel.
  4. Inside a comprehension. sky and rhythm have no a, e, i, o, or u; tree has an e.

Frequently Asked Questions

any() is True only if it finds a truthy item. An empty iterable has none, so the result is False.
any() needs at least one truthy item; all() needs every item to be truthy.
any(word in text for word in words).
No, only True or False. Use next((x for x in items if test(x)), None) to get the match itself.
It does the same work but runs in C and stops at the first match, so it is typically as fast or faster, and shorter.

Next: ascii()

repr() of an object with non-ASCII characters escaped.

ascii() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful