all() always returns True unless there is an element in the sequence that is False.

Your loop produces 0 items, so True is returned.

This is documented:

Return True if all elements of the iterable are true (or if the iterable is empty).

Emphasis mine.

Similarly, any() will always return False, unless an element in the sequence is True, so for empty sequences, any() returns the default:

>>> any(True for _ in '')
False
Answer from Martijn Pieters on Stack Overflow
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ any-and-all
Python's any() and all() functions - Python Morsels
March 29, 2023 - I very much prefer this first approach ... for loop. Python's any function and all function are for checking a condition for every item in a list (or any other iterable)....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-all-function
Python - all() function - GeeksforGeeks
July 23, 2025 - # All elements of tuple are true t = (2, 4, 6) print(all(t)) # All elements of tuple are false t = (0, False, False) print(all(t)) # Some elements of tuple # are true while others are false t = (5, 0, 3, 1, False) print(all(t)) # Empty tuple t = () print(all(t)) # all() with condition - to check if all elements are even l = (2,4,6,8,10) print(all(ele % 2 == 0 for ele in l))
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ built-in โ€บ all
Python all() - Test If All True | Vultr Docs
September 27, 2024 - The all() function in Python is critical for determining whether every element within an iterable (like lists, tuples, or dictionaries) meets a condition, specifically that all elements are True.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_all.asp
Python all() Function
Python Examples Python Compiler ... Certificate Python Training ... The all() function returns True if all items in an iterable are true, otherwise it returns False....
๐ŸŒ
Real Python
realpython.com โ€บ python-all
Python's all(): Check Your Iterables for Truthiness โ€“ Real Python
June 16, 2023 - The loop condition relies on all() to check if all the input lists contain at least one item. In every iteration, the yield statement returns a tuple containing one item from each input list.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
How to Use all() and any() in Python | note.nkmk.me
May 12, 2025 - Passing this result to all() or any() lets you check if all or any elements meet the condition. print(all([i > 2 for i in l])) # False print(any([i > 2 for i in l])) # True ... Changing [] to () creates a generator expression, which returns a generator instead of a list. print(type([i > 2 for i in l])) # <class 'list'> print(type((i > 2 for i in l))) # <class 'generator'> ... When a generator expression is the only argument, you can omit the parentheses and pass it directly to functions like all() or any().
๐ŸŒ
Trey Hunner
treyhunner.com โ€บ 2016 โ€บ 11 โ€บ check-whether-all-items-match-a-condition-in-python
Check Whether All Items Match a Condition in Python
... If we want to use all in this function, we need an iterable (like a list) to pass to all. If we wanted to be really silly, we could make such a list of boolean values like this: ... If youโ€™re familiar with list comprehensions, this code ...
Find elsewhere
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ all
Python all()
Created with over a decade of experience and thousands of feedback. ... Try Programiz PRO! ... Become a certified Python programmer. Try Programiz PRO! ... The all() function returns True if all elements in the given iterable are truthy.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-and-when-to-use-any-and-all-in-python
How and when to use any() and all() in Python
Using a generator inside any() ... printed. Another Python function, all(), accepts an iterable and returns True if all of the elements evaluate to True; if not, it returns False....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-any-and-all-functions-explained-with-examples
Python any() and all() Functions โ€“ Explained with Examples
August 10, 2021 - Now, this is very similar to using an if statement to check if multiple conditions chained by the logical and operator evaluate to True, as shown below: if c1 and c2 and ... c_(N-1) and CN: # DO THIS else: # DO THIS ยท You could use the all() function to make this all the more concise by collecting the conditions in an iterable, and then calling the all() function on the iterable.
๐ŸŒ
Codesarray
codesarray.com โ€บ view โ€บ How-to-use-all()-and-any()-functions-in-Python
How to use all() and any() functions in Python
If every element in the iterable is truthy, all() returns True. If any element is falsy, it returns False. If the iterable is empty, all() returns True, because there are no elements that contradict the condition.
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ any() and all() in python with examples
any() and all() in Python with Examples - Analytics Vidhya
April 1, 2024 - The main difference between any() and all() is their behavior when dealing with iterables. While any() returns True if at least one element satisfies the condition, all() requires all elements to meet the condition to return True.
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ python built-in functions โ€บ python all
Python all() Function by Practical Examples
September 13, 2022 - To make it shorter, you can replace all the and operators with the all() function like this: v = 'Python' valid = all([len(v) > 0, len(v) < 25, v.isalnum()]) if valid: print(v)Code language: Python (python) In this example, The valid evaluates to True if all the conditions inside the tuple passed to the all() the function returns True.
๐ŸŒ
Reddit
reddit.com โ€บ r/pythontips โ€บ how to check if elements in a list meet a specific condition using the 'any' and 'all' functions
r/pythontips on Reddit: How to check if elements in a list meet a specific condition using the 'any' and 'all' functions
March 22, 2024 -

Suppose you have a list of numbers, and you want to check if any of the numbers are greater than a certain value, or if all of the numbers are less than a certain value.

That can be done with this simple code:

# Original list
lst = [1, 2, 3, 4, 5]

# Check if any number is greater than 3
has_greater_than_3 = any(x > 3 for x in lst)

# Check if all numbers are less than 5
all_less_than_5 = all(x < 5 for x in lst)

# Print the results
print(has_greater_than_3)  # True
print(all_less_than_5)   # False

The 'any' function returns True if at least one element meets the condition, and the 'all' function returns True if all elements meet the condition.

๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_all_function.htm
Python all() Function
The Python all() function is a built-in function that returns True if all the elements of a given iterable, such as a list, tuple, set, or dictionary are truthy, and if any of the values is falsy, it returns False.
๐ŸŒ
Wiingy
wiingy.com โ€บ home โ€บ learn โ€บ python โ€บ any() and all() functions in python
Any() and All() Functions in Python (With Examples)
January 30, 2025 - Among these functions are any() and all(). Any() All() function allows us to check whether any or all elements in an iterable object meet certain conditions. In this blog post, we will explore the functionality of these two functions and how ...
๐ŸŒ
Medium
medium.com โ€บ geekculture โ€บ the-all-function-in-python-2ebb701c426
How to use the all Function in Python? | Geek Culture
September 19, 2024 - Learn how to use the Python all function. How to use the all function in Python. What is the all function? Used to check if every element evaluates to true.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python all() function
Python all() Function - Be on the Right Side of Change
December 4, 2020 - According to the official Python ... return False return True ยท So, it goes over all elements in the iterable and uses the element as an if condition to check whether it evaluates to True or False....