Notes

`all()` Function in Python [ English ]

< Prev Next >

1. Introduction

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.

2. Syntax

all(iterable)

Parameter

3. Return Value

4. Basic Example

numbers = [True, True, True]

print(all(numbers))

Output

True

Explanation

5. Example with False Value

values = [True, False, True]

print(all(values))

Output

False

Explanation

6. Example with Numbers

numbers = [1, 2, 3, 4]

print(all(numbers))

Output

True

Explanation

7. Example with Zero

numbers = [1, 2, 0, 4]

print(all(numbers))

Output

False

Explanation

8. Example with Conditions

numbers = [2, 4, 6, 8]

result = all(n % 2 == 0 for n in numbers)

print(result)

Output

True

Explanation

9. Practical Example

marks = [70, 80, 90, 65]

passed = all(mark >= 50 for mark in marks)

print("All students passed:", passed)

Output

All students passed: True

Explanation

10. Summary

< Prev Next >