Python all() built-in function
From the Python 3 documentation
Return True if all elements of the iterable are true (or if the iterable is empty).
Introduction
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.
Examples
# All values are truthy
>>> all([1, 2, 3])
# True
# Contains a falsy value (0)
>>> all([1, 0, 3])
# False
# Contains a falsy value (empty string)
>>> all(['a', '', 'c'])
# False
# An empty iterable is considered True
>>> all([])
# True