Recall & Review
beginner
What does the
any() function do in Python?any() checks if at least one element in an iterable is True. It returns True if any element is true, otherwise False.
Click to reveal answer
beginner
What does the
all() function do in Python?all() checks if every element in an iterable is True. It returns True only if all elements are true, otherwise False.
Click to reveal answer
beginner
What will
any([False, 0, '', None]) return?It returns False because all elements are considered False in Python.
Click to reveal answer
beginner
What will
all([True, 1, 'hello', [1]]) return?It returns True because all elements are considered True in Python.
Click to reveal answer
beginner
How can
any() and all() be useful in real life?They help check conditions quickly, like if any sensor is active (any()) or if all tasks are done (all()), making decisions easier.
Click to reveal answer
What does
any([False, True, False]) return?✗ Incorrect
Since there is at least one True value, any() returns True.
What does
all([True, 1, 'yes']) return?✗ Incorrect
All elements are truthy, so all() returns True.
What will
all([True, False, True]) return?✗ Incorrect
Because one element is False, all() returns False.
Which function returns
True if any element is true?✗ Incorrect
any() returns True if at least one element is true.
What does
any([]) return?✗ Incorrect
any() returns False for empty iterables.
Explain in your own words how
any() works and give a simple example.Think about checking if any light is on in a room.
You got /3 concepts.
Describe how
all() differs from any() and when you might use it.Imagine checking if everyone in a team finished their work.
You got /3 concepts.