Content · Programming · Python

Python any() Function: Usage and Examples

any() returns true when at least one element is truthy, and false for an empty iterable. It works on an iterable and is often clearer than writing a manual accumulation or search loop. See two practical examples, edge.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

A small report summarizes a collection without creating additional indexing logic.

What You Need to Understand


any() returns true when at least one element is truthy, and false for an empty iterable. It works on an iterable and is often clearer than writing a manual accumulation or search loop.

When to Use It


A small report summarizes a collection without creating additional indexing logic.

Step-by-Step Python Example


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

How the Example Works


The first result is True; the empty result is False.

Example Output


True
False
True

A Second Example


Compare this smaller variation with the main example, then experiment with your own values.

values = (value for value in [1, 2, 3])
print(any(values))

Important Behavior and Edge Cases


any() tests truthiness, not whether a collection contains a literal True; nonempty strings and nonzero numbers count as true.

Try It Yourself


Adapt the values and predict the result, then verify it in Python.

Common Beginner Mistakes


  • any() tests truthiness, not whether a collection contains a literal True; nonempty strings and nonzero numbers count as true.
  • Overlooking how an iterable is consumed, how element positions are chosen, or whether a function creates a new list.

Key Takeaways


  • any() returns true when at least one element is truthy, and false for an empty iterable.
  • The first result is True; the empty result is False.
  • any() tests truthiness, not whether a collection contains a literal True; nonempty strings and nonzero numbers count as true.
Share this resourceSend this page to someone who may find it useful.