| title | Python all() built-in function - Python Cheatsheet |
|---|---|
| description | Return True if all elements of the iterable are true (or if the iterable is empty). |
The all() function in Python is a built-in function that checks if all elements in an iterable are True. It returns True if every element evaluates to true, or if the iterable is empty. This is useful for validating conditions across a collection of items, such as checking if all numbers in a list are positive or if all required fields in a form are filled.
# All values are truthy
all([1, 2, 3])
# Contains a falsy value (0)
all([1, 0, 3])
# Contains a falsy value (empty string)
all(['a', '', 'c'])
# An empty iterable is considered True
all([])True
False
False
True
- Cheatsheet: Control Flow
- Cheatsheet: Comprehensions
- Blog: Python Data Types
- any()
- bool()
- list()
- tuple()
- set()
- dict()