Concept
`any()` and `all()`: Quick Collection Checks
`any(seq)` returns `True` if at least one item is truthy. `all(seq)` returns `True` only if every single item is truthy.
python
checks = [True, False, True]
print(any(checks)) # True
print(all(checks)) # False
# 105. `any()` and `all()`: Quick Collection Checks `any(seq)` returns `True` if at least one item is truthy. `all(seq)` returns `True` only if every single item is truthy: ```python checks = [True, False, True] print(any(checks)) # True print(all(checks)) # False ``` Both functions short-circuit: `any()` halts the millisecond it finds its first `True`, and `all()` stops immediately on the first `False`. They never waste CPU cycles scanning the rest of the list.
Checkpoint
What does `all([])` (empty iterable) return in Python?
Practice
Check if any number in `scores = [50, 45, 95, 60]` is greater than 90 using `any()`. Print the boolean result.
01
Tap code blocks below to assemble
Available Blocks