Python Tip of the Day: Quickly Check Conditions with any() and all()
Quickly Check Conditions with any()
and all()
Author: Jeremy Morgan
Published: November 4, 2024
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.
Use any()
and all()
for concise checks over iterables. Super handy!
# Check if any number is even
numbers = [1, 3, 5, 8]
if any(n % 2 == 0 for n in numbers):
print("There's an even number!")
# Output: There's an even number!
The Python Tip of the Day is a daily series published in the month of November. The tips are designed to help you become a better Python programmer. I post tips like this and more every single day on X. Let’s connect!
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.