Python Reference Library →

Python any() Function – Check if Any Element is True

Let’s look at any() function – check if any element is true

  1. Notice

    any() returns True when at least one item is truthy. It returns False for an empty iterable.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
items = [0, 3]
print(any(items))
print(any([]))
Live state

Top-level scope

items→Object 1
Object 1 · list[0, 3]
This step

any() returns True when at least one item is truthy. It returns False for an empty iterable.

Picture any() function – check if any element is true

any() returns True when at least one item is truthy. It returns False for an empty iterable.

Image brief

Alt text
A diagram for Python any() Function – Check if Any Element is True. Instructions: items = [0, 3] print(any(items)) print(any([])). Displayed result: True False. The final example bindings are items --> object 1 (list). object 1: [0, 3]
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python any() Function – Check if Any Element is True". Teaching focus: any() returns True when at least one item is truthy. It returns False for an empty iterable. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS items = [0, 3] print(any(items)) print(any([])) | v DISPLAYED RESULT True False FINAL BINDINGS items --> object 1 (list) object 1: [0, 3] Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python any() Function – Check if Any Element is True. Instructions: items = [0, 3] print(any(items)) print(any([])). Displayed result: True False. The final example bindings are items --> object 1 (list). object 1: [0, 3]

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
items = [0, 3]
print(any(items))
print(any([]))
Live state

Top-level scope

items→Object 1
Object 1 · list[0, 3]
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
True
False

What do you expect this program to print?

What does this example display?

items = [0, 3]
print(any(items))
print(any([]))
What does this example display?
Choose one answer. You can try again.

Answer and explanation

True False

Follow the printed values in order. The output is: True False

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

any() returns True when at least one item is truthy. It returns False for an empty iterable.

any() returns True when at least one item is truthy. It returns False for an empty iterable.

More examples and reference

Python any() Function

The any() function in Python is used to check if at least one element in an iterable (like a list, tuple, or set) is True. If it finds even one True value, it immediately returns True.

Syntax

any(iterable)

Parameters:

  • iterable – A list, tuple, set, string, dictionary, or any iterable containing values.

Returns:

  • True – if at least one element is true (non-zero or non-empty)
  • False – if all elements are false (zero, empty, or None)

Example 1: List with One True Value

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

Example 2: All False Values

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

Example 3: Using any() with Strings

words = ["", "", "hello"]
print(any(words))
True

Because "hello" is non-empty, it's considered True.

Use Case: Check if Any Input Field is Filled

name = ""
email = "example@example.com"
phone = ""

if any([name, email, phone]):
    print("At least one field is filled.")
else:
    print("All fields are empty.")
At least one field is filled.

How any() Works Internally

  • It checks each item from left to right.
  • Stops as soon as it finds the first True value (short-circuiting).
  • Returns False if no True values are found.

Common Mistakes

  • Passing non-iterable like any(5) → ❌ Raises TypeError
  • Expecting it to check if values are equal or valid — it only checks truthiness

Interview Tip

any() is often used to simplify conditional checks across multiple values. It helps avoid writing long or chains like if a or b or c.

Summary

  • any() returns True if at least one value is truthy.
  • Works on lists, tuples, sets, dictionaries, strings, etc.
  • Stops early when it finds the first True.

Practice Problem

Write a program that checks if any number in a list is greater than 10:

numbers = [2, 5, 8, 12, 4]
result = any(n > 10 for n in numbers)
print("Any number > 10?", result)
Any number > 10? True

What to remember

Connect what you noticed in the example with the idea below.

Remember

any() returns True when at least one item is truthy. It returns False for an empty iterable.

Watch out for this idea

any([]) returns True.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →