Python Reference Library →

Python all() Function – Check If All Elements Are True

Let’s look at all() function – check if all elements are true

  1. Notice

    all() tests whether every item is truthy. It returns True for an empty iterable.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
items = [3, 1]
print(all(items))
print(all([]))
Live state

Top-level scope

items→Object 1
Object 1 · list[3, 1]
This step

all() tests whether every item is truthy. It returns True for an empty iterable.

Picture all() function – check if all elements are true

all() tests whether every item is truthy. It returns True for an empty iterable.

Image brief

Alt text
A diagram for Python all() Function – Check If All Elements Are True. Instructions: items = [3, 1] print(all(items)) print(all([])). Displayed result: True True. The final example bindings are items --> object 1 (list). object 1: [3, 1]
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python all() Function – Check If All Elements Are True". Teaching focus: all() tests whether every item is truthy. It returns True for an empty iterable. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS items = [3, 1] print(all(items)) print(all([])) | v DISPLAYED RESULT True True FINAL BINDINGS items --> object 1 (list) object 1: [3, 1] Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python all() Function – Check If All Elements Are True. Instructions: items = [3, 1] print(all(items)) print(all([])). Displayed result: True True. The final example bindings are items --> object 1 (list). object 1: [3, 1]

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
items = [3, 1]
print(all(items))
print(all([]))
Live state

Top-level scope

items→Object 1
Object 1 · list[3, 1]
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
True
True

What do you expect this program to print?

What does this example display?

items = [3, 1]
print(all(items))
print(all([]))
What does this example display?
Choose one answer. You can try again.

Answer and explanation

True True

Follow the printed values in order. The output is: True True

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

all() tests whether every item is truthy. It returns True for an empty iterable.

all() tests whether every item is truthy. It returns True for an empty iterable.

More examples and reference

Python all() Function

The all() function in Python checks whether all elements in an iterable are true. If they are, it returns True. Otherwise, it returns False.

Syntax

all(iterable)

Parameters:

  • iterable – A list, tuple, set, dictionary, or any iterable object.

Returns:

  • True – If all elements in the iterable are true (or the iterable is empty)
  • False – If any element is false

Example 1: Using all() with a List of Booleans

values = [True, True, True]
print(all(values))
True

Example 2: With One False Value

values = [True, False, True]
print(all(values))
False

Example 3: Checking Numbers (Zero is False)

numbers = [1, 2, 3, 0]
print(all(numbers))
False

0 is considered False in Python.

Example 4: Empty Iterable

print(all([]))
True

This might seem strange, but in logic, a universal statement about an empty set is considered true.

Use Case: All Elements Greater Than 0

nums = [5, 8, 12, 3]
result = all(n > 0 for n in nums)
print(result)
True

Use Case: Validating All Inputs

inputs = ["name", "email", ""]
print(all(inputs))
False

This is useful in form validation — one empty string makes all() return False.

Common Mistakes

  • Passing non-iterables like integers will raise a TypeError
  • Assuming all() checks a condition itself — it only evaluates the truthiness of elements

Interview Tip

all() is often used with list comprehensions or generator expressions to verify conditions across a dataset.

Summary

  • all() returns True only if every element is true
  • 0, False, "", [], etc., are considered false
  • Very useful for condition checks and validation

Practice Problem

Write a program that takes a list of ages and prints "All adults" if all are 18 or older.

ages = [22, 34, 19, 45]
if all(age >= 18 for age in ages):
    print("All adults")
else:
    print("Not all are adults")

What to remember

Connect what you noticed in the example with the idea below.

Remember

all() tests whether every item is truthy. It returns True for an empty iterable.

Watch out for this idea

all([]) returns False.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →