Python any() Function Explained

any() is a built-in Python function that checks an iterable and tells you whether at least one item is truthy.

You will usually use it with values like:

  • lists
  • tuples
  • sets
  • strings
  • generator expressions

It is useful when you want a quick True or False answer without writing a full loop.

values = [0, '', 5]
print(any(values))  # True

Use any(iterable) when you want True if at least one item in the iterable is truthy.

What any() does

any() checks an iterable such as a list, tuple, set, or generator.

It returns:

  • True if at least one item is truthy
  • False if all items are falsy
  • False if the iterable is empty

This makes it a good choice for simple checks like:

  • "Does this list contain at least one real value?"
  • "Does any number match this condition?"
  • "Is there at least one non-empty string?"

If you want the opposite behavior, where every item must be truthy, see all().

Syntax

The syntax is simple:

any(iterable)

The argument must be an iterable.

Common inputs include:

  • lists
  • tuples
  • sets
  • strings
  • generator expressions

For example:

print(any([0, 0, 1]))
print(any((False, False)))
print(any({0, 2}))
print(any("hello"))

Expected output:

True
False
True
True

If you are not sure what an iterable is, read iterators and iterable objects explained.

What truthy and falsy mean

In Python, values are often treated as either truthy or falsy in conditions.

  • Truthy values act like True
  • Falsy values act like False

Common falsy values include:

  • False
  • 0
  • 0.0
  • ''
  • []
  • {}
  • set()
  • None

Most other values are truthy.

That means these values are truthy:

print(any([1]))
print(any(['hello']))
print(any([[1, 2, 3]]))

Expected output:

True
True
True

And these are all falsy:

print(any([0, '', None]))

Expected output:

False

If you want to understand this more clearly, see Python booleans explained: true and false and bool() explained.

Basic example

Here is a simple example with one truthy value:

values = [0, '', 5]
print(any(values))

Output:

True

Why?

  • 0 is falsy
  • '' is falsy
  • 5 is truthy

Since at least one item is truthy, any(values) returns True.

Now look at a list where every item is falsy:

values = [0, '', None, False]
print(any(values))

Output:

False

Here, none of the items are truthy, so the result is False.

Using any() with conditions

any() is often used with a generator expression.

This is a common pattern:

any(condition for item in items)

It is useful when you want to check whether any item matches a rule.

For example, to check whether any number is negative:

numbers = [4, 7, -2, 10]

result = any(x < 0 for x in numbers)
print(result)

Output:

True

This works because x < 0 is checked for each number:

  • 4 < 0False
  • 7 < 0False
  • -2 < 0True

As soon as Python finds one True result, any() can return True.

Here is another example:

words = ["apple", "", "banana"]

has_empty_string = any(word == "" for word in words)
print(has_empty_string)

Output:

True

This style is often cleaner than writing a full loop for a simple match check. For related list-checking examples, see how to check if a value exists in a list in Python.

Empty iterables

An empty iterable returns False:

print(any([]))

Output:

False

This can surprise beginners.

The reason is simple: any() looks for at least one truthy item. In an empty iterable, there are no items at all, so there is nothing truthy to find.

The same idea applies to other empty iterables:

print(any(()))
print(any(""))
print(any(set()))

Output:

False
False
False

When to use any()

Use any() when you want to:

  • check whether a list contains at least one matching value
  • simplify loops that only need one match
  • make condition checks shorter and easier to read

For example, instead of writing this:

numbers = [1, 3, 5, 8]

found_even = False

for number in numbers:
    if number % 2 == 0:
        found_even = True
        break

print(found_even)

You can write:

numbers = [1, 3, 5, 8]
print(any(number % 2 == 0 for number in numbers))

Both work, but any() is shorter and easier to read when you only need a yes-or-no answer.

Common beginner mistakes

Here are some common mistakes with any().

Passing a single number instead of an iterable

This is wrong:

print(any(5))

It causes an error because 5 is not iterable.

Use an iterable instead:

print(any([5]))

Thinking any() checks whether all values are True

any() needs only one truthy item.

print(any([False, False, True]))

Output:

True

If you need every item to be truthy, use all() instead.

Forgetting that non-empty strings are truthy

A non-empty string is truthy, even if it is not "True".

print(any(["False"]))

Output:

True

That is because "False" is a non-empty string.

Using a list comprehension when a generator expression is enough

This works:

numbers = [1, 2, 3]
print(any([x > 2 for x in numbers]))

But this is usually better:

numbers = [1, 2, 3]
print(any(x > 2 for x in numbers))

The second version avoids creating an unnecessary list.

FAQ

What does any() return in Python?

It returns True if at least one item in the iterable is truthy. Otherwise it returns False.

What happens if the iterable is empty?

any() returns False for an empty iterable.

What is the difference between any() and all()?

any() needs one truthy item. all() needs every item to be truthy.

Can I use any() with a condition?

Yes. A common pattern is:

any(condition for item in items)

For example:

numbers = [1, 2, 3]
print(any(x > 2 for x in numbers))

See also