The all() function in Python is a built-in function used to check whether all elements in an iterable are True. It returns True only if every element in the iterable evaluates to True. If any element is False, the function returns False.
The all() function is commonly used when a program needs to verify that all conditions in a sequence are satisfied.
all(iterable)
numbers = [True, True, True]
print(all(numbers))
Output
True
Explanation
True, so the function returns True.values = [True, False, True]
print(all(values))
Output
False
Explanation
False, the function returns False.numbers = [1, 2, 3, 4]
print(all(numbers))
Output
True
Explanation
True.numbers = [1, 2, 0, 4]
print(all(numbers))
Output
False
Explanation
0 is considered False in Python.False.numbers = [2, 4, 6, 8]
result = all(n % 2 == 0 for n in numbers)
print(result)
Output
True
Explanation
True.marks = [70, 80, 90, 65]
passed = all(mark >= 50 for mark in marks)
print("All students passed:", passed)
Output
All students passed: True
Explanation
all() is a built-in Python function used to check whether all elements in an iterable are True.