all() is a built-in Python function that returns True if **all** elements in an iterable are truthy (or the iterable is empty), and False otherwise. It short-circuits — stops as soon as it finds a falsy value — making it efficient for early exit checks. In 2026, all() remains essential across data science (validating arrays, checking conditions), software engineering (input validation, guard clauses), and functional pipelines (filtering invariants, predicate composition) — vectorized in NumPy/Dask/Polars for large data, and naturally parallel-friendly when combined with map/filter/reduce patterns.
Here’s a complete, practical guide to using all() in Python: basic usage, truthy/falsy behavior, NumPy/Dask/Polars vectorization, real-world patterns (earthquake data validation, condition checks), and modern best practices with type hints, performance, edge cases, and alternatives.
Basic all() — checks if every element is truthy; empty iterables return True.
print(all([True, True, True])) # True
print(all([1, 2, 3])) # True (non-zero ints are truthy)
print(all([1, 0, 3])) # False (0 is falsy)
print(all([])) # True (empty is True by convention)
print(all([1, 2, None])) # False (None is falsy)
print(all("hello")) # True (non-empty strings are truthy)
print(all("")) # False (empty string is falsy)
all() with NumPy/Dask/Polars — vectorized checks on arrays/Series.
import numpy as np
import dask.array as da
import polars as pl
# NumPy: all elements > 0
arr = np.array([1, 2, 3, -1])
print(np.all(arr > 0)) # False
# Dask: lazy parallel check
darr = da.from_array(arr, chunks=2)
print(darr.all().compute()) # False (all elements truthy? No)
# Polars: Series all
s = pl.Series([True, True, False])
print(s.all()) # False
# Real usage: validate no missing values in key columns
df = pl.DataFrame({"mag": [6.1, 7.2, None, 5.8]})
print(df["mag"].is_not_null().all()) # False
Real-world pattern: earthquake data validation — use all() to check conditions across records.
import pandas as pd
df = pd.read_csv('earthquakes.csv')
# Check all events have required fields
required_cols = ['time', 'latitude', 'longitude', 'mag', 'depth']
has_all_cols = all(col in df.columns for col in required_cols)
print(f"All required columns present: {has_all_cols}")
# Check no negative magnitudes or impossible depths
valid_ranges = all([
(df['mag'] >= 0).all(),
(df['depth'] >= 0).all(),
(df['latitude'].between(-90, 90)).all(),
(df['longitude'].between(-180, 180)).all()
])
print(f"All events in valid ranges: {valid_ranges}")
# Dask version (large data)
ddf = dd.read_csv('large_earthquakes.csv', assume_missing=True)
valid = ddf.map_partitions(lambda df: pd.Series({
'mag_nonneg': (df['mag'] >= 0).all(),
'depth_nonneg': (df['depth'] >= 0).all()
})).compute()
print(valid.all()) # True if all partitions pass
Best practices for all() in Python & data workflows. Use all() for validation — guard clauses, preconditions, postconditions. Modern tip: use Polars .all() — fast columnar checks; Dask .all() for distributed arrays. Prefer all() over loops — clearer, often faster. Short-circuiting — all() stops at first falsy value. Use with comprehensions — all(x > 0 for x in lst). Handle empty iterables — returns True (vacuous truth). Add type hints — def all_positive(numbers: list[float]) -> bool. Use NumPy np.all() — vectorized array checks. Use Dask darr.all() — parallel array checks. Use Polars pl.col('col').all() — columnar boolean reduction. Use all() in assertions — assert all(df['mag'] >= 0). Use all() with map — all(map(is_valid, items)). Profile performance — timeit for large lists. Use operator.and_ — in reduce for custom all-like ops. Handle NaN/inf — np.all(np.isfinite(arr)) for numeric validation.
all() returns True if every element in an iterable is truthy (or empty) — built-in for iterables, vectorized in NumPy/Dask/Polars for arrays. In 2026, use for validation, filtering checks, and condition composition — short-circuiting, lazy when possible, and integrate with pandas/Polars/Dask pipelines. Master all(), and you’ll write concise, efficient, readable checks for any data or logic flow.
Next time you need to verify every item satisfies a condition — use all(). It’s Python’s cleanest way to say: “Are all of these true? — stop at the first False.”