any() is a built-in Python function that returns True if **at least one** element in an iterable is truthy (non-empty iterables only; empty returns False). It short-circuits — stops as soon as it finds a truthy value — making it efficient for early-exit checks. In 2026, any() remains essential across data science (existence checks, validation), software engineering (guard conditions, any-match predicates), and functional pipelines — vectorized in NumPy/Dask/Polars for large arrays/Series, and naturally parallel-friendly when used with map/filter/reduce patterns.
Here’s a complete, practical guide to using any() in Python: basic usage, truthy/falsy behavior, NumPy/Dask/Polars vectorization, real-world patterns (earthquake data checks, condition validation), and modern best practices with type hints, performance, edge cases, and alternatives.
Basic any() — returns True if any element is truthy; empty iterable returns False.
print(any([False, False, True, False])) # True
print(any([0, 0, 0, 0])) # False (all falsy)
print(any([0, 0, 1, 0])) # True
print(any([])) # False (empty)
print(any([None, None, "hello"])) # True
print(any("")) # False (empty string)
print(any("abc")) # True (non-empty string)
any() with NumPy/Dask/Polars — vectorized checks on arrays/Series.
import numpy as np
import dask.array as da
import polars as pl
# NumPy: any element > 0
arr = np.array([-5, 3, -2, 0, 7, -1.5])
print(np.any(arr > 0)) # True
# Dask: lazy parallel check
darr = da.from_array(arr, chunks=2)
print(darr.any().compute()) # True (any truthy? Yes)
# Polars: Series any
s = pl.Series([False, False, True, False])
print(s.any()) # True
# Real usage: check if any magnitude ? 8
df = pl.DataFrame({"mag": [6.1, 7.2, 5.8, 8.1]})
print(df["mag"].ge(8).any()) # True
Real-world pattern: earthquake data validation & filtering — use any() to check conditions across records.
import pandas as pd
df = pd.read_csv('earthquakes.csv')
# Check if any event has magnitude ? 8
has_major = any(df['mag'] >= 8)
print(f"Any major earthquake (M?8): {has_major}")
# Check if any required column is entirely missing
required = ['time', 'latitude', 'longitude', 'mag', 'depth']
missing_cols = any(col not in df.columns for col in required)
print(f"Any required column missing: {missing_cols}")
# Dask version (large data)
ddf = dd.read_csv('large_earthquakes.csv', assume_missing=True)
has_major_dask = ddf['mag'].ge(8).any().compute()
print(f"Any M?8 event: {has_major_dask}")
# Polars: fast columnar check
pl_df = pl.read_csv('earthquakes.csv')
print(pl_df["mag"].ge(8).any()) # True/False
Best practices for any() in Python & data workflows. Use any() for existence checks — guard clauses, early exits, validation. Modern tip: use Polars .any() — fast columnar checks; Dask .any() for distributed arrays. Prefer any() over loops — clearer, often faster. Short-circuiting — any() stops at first truthy value. Use with comprehensions — any(x > 0 for x in lst). Handle empty iterables — returns False. Add type hints — def has_major_quake(df: pd.DataFrame) -> bool. Use NumPy np.any() — vectorized array checks. Use Dask darr.any() — parallel array checks. Use Polars pl.col('col').any() — columnar boolean reduction. Use any() in assertions — assert any(df['mag'] >= 7). Use any() with map — any(map(is_valid, items)). Profile performance — timeit for large lists. Use operator.or_ — in reduce for custom any-like ops. Handle NaN/inf — np.any(np.isnan(arr)) for missing checks.
any() returns True if any element in an iterable is truthy — built-in for iterables, vectorized in NumPy/Dask/Polars for arrays. In 2026, use for validation, existence checks, and condition composition — short-circuiting, lazy when possible, and integrate with pandas/Polars/Dask pipelines. Master any(), and you’ll write concise, efficient, readable checks for any data or logic flow.
Next time you need to check if at least one item satisfies a condition — use any(). It’s Python’s cleanest way to say: “Is there any true value? — stop at the first True.”