When I build small reporting scripts, I often need a quick answer to one question: “Does at least one record need attention?” For example, a sales report may contain hundreds of orders, but I only need to know whether any order has a missing customer email or an amount above an approval limit.
That is exactly where the Python any() function helps. Instead of writing a long loop and tracking a separate flag variable, you can test a collection in one clean line.
In this guide, you will learn how the Python any() function works, where to use it, and how to avoid the mistakes I see most often in beginner scripts.
What Is the Python any() Function?
The Python any() function checks an iterable and returns True when it finds at least one truthy value.
An iterable is any Python object you can loop through, such as a list, tuple, set, string, dictionary, or generator. A value is truthy when Python treats it as true in a condition. Common truthy values include non-zero numbers, non-empty strings, and True.
Here is the syntax:
any(iterable)
The function returns:
Truewhen at least one item is truthyFalsewhen every item is falsyFalsewhen the iterable is empty
Falsy values commonly include:
False
0
0.0
""
[]
{}
None
The Python any() function is useful when you need to check whether one or more values meet a condition. It works especially well in automation scripts, data validation, CSV cleanup, API response checks, and reporting tools.
If you are new to Python functions, start by learning how to define a function in Python and how to call a function in Python.
Python any() Function With a Simple List
Let’s start with a list of boolean values. This is the easiest way to understand how any() works.
payment_statuses = [False, False, True, False]
has_completed_payment = any(payment_statuses)
print(has_completed_payment)
Output:
True
You can see the output in the screenshot below.

The list contains one True value. Because the Python any() function only needs one truthy item, it returns True.
In a real script, this pattern can help when you store validation results from several checks.
has_name = True
has_email = True
has_shipping_address = False
checkout_ready = any([has_name, has_email, has_shipping_address])
print(checkout_ready)
Output:
True
This result means at least one field contains a value. However, this does not mean the checkout form is fully valid. To make sure every required field passes validation, use all() instead of any().
has_name = True
has_email = True
has_shipping_address = False
checkout_ready = all([has_name, has_email, has_shipping_address])
print(checkout_ready)
Output:
False
You can see the output in the screenshot below.

Use any() when one valid result is enough. Use all() when every condition must pass.
Pro Tip: In my experience, developers often use
any()when they really needall(). Before writing the condition, say the requirement aloud: “At least one is valid” meansany(), while “Every required field is valid” meansall().
Python any() Function With Numbers
Python treats non-zero numbers as truthy and zero as falsy. You can use the Python any() function to check whether a list contains at least one non-zero number.
weekly_sales = [0, 0, 0, 250, 0]
has_sales = any(weekly_sales)
print(has_sales)
Output:
True
You can see the output in the screenshot below.

The value 250 is non-zero, so Python treats it as true.
Now look at a list with only zeros.
weekly_sales = [0, 0, 0, 0]
has_sales = any(weekly_sales)
print(has_sales)
Output:
False
This pattern works well in a local reporting script. For example, suppose Jordan runs a weekly sales report for a small store in Austin. The script can quickly check whether any representative made a sale.
sales_by_representative = {
"Emma Davis": 0,
"Noah Wilson": 0,
"Olivia Martinez": 475,
"Liam Johnson": 0
}
has_team_sales = any(sales_by_representative.values())
print(has_team_sales)Output:
True
The .values() method gives you the dictionary values. Since Olivia has sales of 475, the expression returns True.
To learn more about dictionaries, see how to initialize a dictionary in Python and how to update values in a Python dictionary.
Python any() Function With Conditions
The most practical use of the Python any() function is checking a condition across many items.
For example, imagine you have a list of order amounts. Your reporting script needs to identify whether any order needs manager approval because it exceeds $1,000.
order_amounts = [245, 650, 1200, 89, 430]
needs_manager_approval = any(amount > 1000 for amount in order_amounts)
print(needs_manager_approval)
Output:
True
The expression inside any() checks each amount:
amount > 1000
Python creates the results one at a time. When it reaches 1200, the condition becomes True. The function then returns True.
This style uses a generator expression. A generator expression produces values when Python needs them, instead of creating a full temporary list first. That makes it a good option for large datasets.
Here is the same logic written with a regular loop:
order_amounts = [245, 650, 1200, 89, 430]
needs_manager_approval = False
for amount in order_amounts:
if amount > 1000:
needs_manager_approval = True
break
print(needs_manager_approval)
Output:
True
Both examples work, but the any() version is shorter and communicates the intent more clearly.
needs_manager_approval = any(amount > 1000 for amount in order_amounts)
Use this approach when you need a yes-or-no answer. If you need the actual matching order amount, use a loop or next() instead.
You may also find how to filter lists in Python useful when you need to keep every matching value instead of checking for one.
Check for Missing Values With Python any()
Data cleanup scripts often need to detect missing values before they save a report or upload records to another system.
Here is a simple customer record example.
customer = {
"name": "Michael Carter",
"email": "",
"phone": "555-0148",
"city": "Denver"
}
has_missing_required_value = any(
not customer[field]
for field in ["name", "email", "phone"]
)
print(has_missing_required_value)Output:
True
The email value is an empty string. Empty strings are falsy, so not customer["email"] becomes True.
This check is useful before you write customer data to a CSV file, send an email, or make an API request.
Here is a more readable version that also identifies the missing fields.
customer = {
"name": "Michael Carter",
"email": "",
"phone": "555-0148",
"city": "Denver"
}
required_fields = ["name", "email", "phone"]
missing_fields = [
field
for field in required_fields
if not customer[field]
]
has_missing_required_value = any(missing_fields)
print("Missing required values:", has_missing_required_value)
print("Missing fields:", missing_fields)Output:
Missing required values: True
Missing fields: ['email']
The first list comprehension creates a list of missing fields. Then any(missing_fields) checks whether the list contains at least one item.
If you work with text input, review how to check if a string is empty in Python and how to remove spaces from a string in Python. A string containing only spaces looks non-empty until you clean it with .strip().
Python any() Function With Strings
You can use the Python any() function to check individual characters in a string. This is helpful for password validation, file name checks, and simple user-input rules.
For example, this script checks whether a password contains at least one digit.
password = "RiverStone!"
has_number = any(character.isdigit() for character in password)
print(has_number)
Output:
False
The password contains letters and a special character, but it does not contain a digit.
Now add a number.
password = "RiverStone9!"
has_number = any(character.isdigit() for character in password)
print(has_number)
Output:
True
The .isdigit() string method returns True when a character is a digit.
You can also check for special characters.
password = "RiverStone9!"
special_characters = "!@#$%^&*"
has_special_character = any(
character in special_characters
for character in password
)
print(has_special_character)
Output:
True
This code checks every character in the password. It returns True as soon as it finds !.
For a fuller validation workflow, see how to validate passwords in Python and how to validate email addresses in Python.
Pro Tip: I always strip user input before checking it. A value like
" "is technically non-empty, but it is not meaningful input. Usevalue.strip()before yourany()validation checks when users can type free-form text.
Python any() Function With Dictionaries
When you pass a dictionary directly to any(), Python checks its keys, not its values.
project_tasks = {
"draft_report": False,
"send_invoice": False,
"review_budget": True
}
result = any(project_tasks)
print(result)Output:
True
This result may surprise you. The dictionary contains keys, and non-empty strings are truthy. Since "draft_report" is a non-empty string, any(project_tasks) returns True.
If you want to check the dictionary values, use .values().
project_tasks = {
"draft_report": False,
"send_invoice": False,
"review_budget": True
}
has_pending_task = any(project_tasks.values())
print(has_pending_task)Output:
True
This version checks False, False, and True, which gives the result you expect.
You can also check whether any employee has an overdue task.
employee_tasks = {
"Sophia Brown": {"overdue": False, "open_tasks": 3},
"Ethan Miller": {"overdue": True, "open_tasks": 5},
"Ava Thompson": {"overdue": False, "open_tasks": 1}
}
has_overdue_task = any(
task_data["overdue"]
for task_data in employee_tasks.values()
)
print(has_overdue_task)Output:
True
This is a useful pattern when you receive nested JSON data from an internal system. If you want to prepare JSON data in Python, see how to work with JSON data in Python and how to convert a Python dictionary to JSON.
Python any() Function With a List of Dictionaries
Many real-world scripts process a list of dictionaries. Each dictionary often represents one row from a CSV file, API response, spreadsheet, or database query.
Let’s check whether any sales order has a missing email address.
orders = [
{
"order_id": "ORD-1001",
"customer": "Mia Anderson",
"email": "mia.anderson@example.com",
"amount": 450
},
{
"order_id": "ORD-1002",
"customer": "Benjamin Hall",
"email": "",
"amount": 720
},
{
"order_id": "ORD-1003",
"customer": "Grace Taylor",
"email": "grace.taylor@example.com",
"amount": 1100
}
]
has_missing_email = any(
not order["email"]
for order in orders
)
print(has_missing_email)
Output:
True
The second order has an empty email value, so the result is True.
Now let’s create a more complete reporting script. It checks whether any order needs manager approval and whether any customer record has missing contact information.
orders = [
{
"order_id": "ORD-1001",
"customer": "Mia Anderson",
"email": "mia.anderson@example.com",
"amount": 450
},
{
"order_id": "ORD-1002",
"customer": "Benjamin Hall",
"email": "",
"amount": 720
},
{
"order_id": "ORD-1003",
"customer": "Grace Taylor",
"email": "grace.taylor@example.com",
"amount": 1100
}
]
has_missing_email = any(
not order["email"].strip()
for order in orders
)
has_high_value_order = any(
order["amount"] > 1000
for order in orders
)
print("Orders with missing email:", has_missing_email)
print("Orders requiring approval:", has_high_value_order)
Output:
Orders with missing email: True
Orders requiring approval: True
The .strip() method removes spaces from the email value before Python checks it. That matters because " " is truthy before cleanup, even though it is not a usable email address.
If your data comes from a CSV file, you can also explore how to read large CSV files in Python and how to create a CSV file in Python.
Why Python any() Function Stops Early
The Python any() function uses short-circuit evaluation. That means it stops checking as soon as it finds a truthy value.
Consider this example:
def check_order(order_amount):
print(f"Checking order amount: {order_amount}")
return order_amount > 1000
order_amounts = [250, 1200, 5000, 300]
needs_approval = any(
check_order(amount)
for amount in order_amounts
)
print("Needs approval:", needs_approval)
Output:
Checking order amount: 250
Checking order amount: 1200
Needs approval: True
Python checks 250 first, but that value does not exceed the approval limit. Next, it checks 1200, which passes the condition. At that point, any() returns True and does not check 5000 or 300.
This behavior can improve performance when you work with large lists, log files, or database records. It also means you should avoid adding important actions inside the condition.
For example, do not use any() if your code must process or save every record. Use a normal for loop instead.
Python any() Function vs a for Loop
Both approaches can answer the same question, but each suits a different job.
| Situation | Use any() | Use a for loop |
|---|---|---|
You only need a True or False answer | Yes | Not usually needed |
| You need the first matching item | Sometimes, with next() | Yes |
| You need every matching item | No | Yes |
| You need to update or save each item | No | Yes |
| You want a short validation expression | Yes | Sometimes |
| You need clear debugging output for every item | Usually no | Yes |
Here is an example where a loop makes more sense because you need the actual records.
orders = [
{"order_id": "ORD-1001", "amount": 450},
{"order_id": "ORD-1002", "amount": 1200},
{"order_id": "ORD-1003", "amount": 1750}
]
high_value_orders = []
for order in orders:
if order["amount"] > 1000:
high_value_orders.append(order)
print(high_value_orders)
Output:
[{'order_id': 'ORD-1002', 'amount': 1200}, {'order_id': 'ORD-1003', 'amount': 1750}]Use any() when your script only needs to decide whether at least one match exists. Use a loop or list comprehension when you need to collect or change matching records.
Things to Keep in Mind
- Use generator expressions for large data: Write
any(item > 100 for item in items)instead of creating a temporary list with square brackets. Python checks values one at a time and can stop early. - Remember that empty iterables return False:
any([]),any(()), andany({})all returnFalse. Handle an empty input separately if it means something different in your script. - Check dictionary values explicitly:
any(my_dict)checks keys. Useany(my_dict.values())when you want to evaluate dictionary values. - Clean text before validation: Use
.strip()for user input and CSV fields. Otherwise, strings containing spaces may pass a truthiness check incorrectly. - Do not use any() for side effects: Since
any()stops after the first truthy result, avoid sending emails, updating files, or changing database records inside its condition. - Choose all() when every rule matters: If each required field or every test must pass, use
all()rather thanany().
Frequently Asked Questions
What does any() do in Python?
The Python any() function returns True when at least one item in an iterable is truthy. It returns False when all items are falsy or when the iterable is empty.
Does Python any() work with an empty list?
Yes. The expression any([]) works and returns False. Python finds no truthy values because the list has no items.print(any([]))
Output:False
What is the difference between any() and all() in Python?
Use any() when at least one condition must be true. Use all() when every condition must be true.values = [True, True, False]
print(any(values))
print(all(values))
Output:True
False
Does any() check every item in a list?
Not always. Python stops as soon as it finds the first truthy item. This behavior is called short-circuit evaluation and can make checks faster.
Can I use any() with a dictionary?
Yes, but any(dictionary) checks dictionary keys. Use any(dictionary.values()) to check values and any(condition for key, value in dictionary.items()) for custom checks.
Can I use any() to check whether a list contains a value?
Yes. Use a condition inside a generator expression.colors = ["blue", "green", "red"]
has_red = any(color == "red" for color in colors)
print(has_red)
Output:True
The Python any() function gives you a clean way to test whether at least one value or condition is true. Start with simple lists, then use generator expressions for validation and automation scripts that process real data.
Use any() when you only need a yes-or-no result, and switch to a loop when you need the matching records themselves. I hope you found this practical guide helpful.
You May Also Like
- Built-in functions in Python
- Python map() function examples
- Check if any element in one list exists in another list
- How to remove None values from a Python list
- Python return statement explained

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.