October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Python any() Function: A Practical Guide With Examples

Python’s any() returns True if an iterable contains at least one truthy item, and False if it contains none or is empty. See examples, truthiness rules, and how it compares with all().
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python’s built-in any() returns True when at least one item in an iterable is truthy; it returns False if none are truthy or the iterable is empty. It returns a Boolean, not the item that matched, and requires no import.

How any() works

Pass any() an iterable, such as a list, tuple, or generator. Python checks each element using its usual truth-value rules and stops as soon as it finds a truthy one. If iteration finishes without finding one, the result is False.

As an Amazon Associate I earn from qualifying purchases.

any([False, False, True])  # True
any([0, "", None])         # False
any([])                    # False

That behavior is captured by the documented equivalent:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
def any(iterable):
    for element in iterable:
        if element:
            return True
    return False

This is a conceptual equivalent, not code you need to define: any() is already available as a Python built-in.

What counts as true?

any() does not look only for the literal value True. It tests each item according to Python’s truth-value rules. For built-in values, zero, an empty string, and None are false; nonzero numbers and non-empty strings are true. By default, an object is true unless its class defines __bool__() to return False or defines __len__() to return zero. See the Python 3.14.7 built-in types documentation for these rules.

If a custom truth-testing method raises an exception, that exception propagates; any() does not convert it into False.

Use a predicate when you have a specific condition

When the question is whether any item meets a condition, put that condition in a generator expression. Each generated result is then truth-tested by any().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
numbers = [1, 3, 8]
any(number > 5 for number in numbers)  # True

This asks whether at least one number is greater than five. The generator expression yields a Boolean for each number, and iteration can stop at the first True.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How any() differs from all()

Use any() for an “at least one” question and all() for an “every item” question. Both return Booleans, but their results for an empty iterable differ:

Function Question Result for an empty iterable
any(iterable) Is at least one item truthy? False
all(iterable) Are all items truthy? True

The Python built-in functions reference documents both behaviors and provides the equivalent loop for any().

Common mistakes to avoid

  • Expecting the matching item: any() returns only True or False; it does not return the first truthy element.
  • Looking only for literal True: any truthy value can make the result true, including a nonzero number or non-empty string.
  • Passing a non-iterable: the argument must be iterable; a scalar value by itself is not a valid input.
  • Using truthiness when the rule is narrower: express the intended test directly in a generator expression, such as any(item > threshold for item in items).

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.