Using all() and any() for Boolean Tests in Python


Check if all or any items in a collection meet a condition.

Source Code

all_even = all(x % 2 == 0 for x in numbers)
any_even = any(x % 2 == 0 for x in numbers)
print(f"All even: {all_even}, Any even: {any_even}")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments