![]() |
VOOZH | about |
Any and All are two built-in functions provided in Python used for successive And/Or. In this article, we will see about any and all in Python.
Any Returns true if any of the items is True and returns False if empty or all are false. Any can be thought of as a sequence of OR operations on the provided iterables. It short circuit the execution i.e. stop the execution as soon as the result is known.
Syntax: any(list of iterables)
In the below example, we are showing any() function's working and demonstration by using the below code.
False True True
In this another example, we are given two lists and we are seeing if any of the number in the list is divisible by 5 by using any function.
See whether at least one number is divisible by 5 in list 1=> True
All Returns true if all of the items are True (or if the iterable is empty). All can be thought of as a sequence of AND operations on the provided iterables. It also short circuit the execution i.e. stop the execution as soon as the result is known.
Syntax: all(list of iterables)
In the below example, we are showing the demonstration and working of the all() function with the help of code below.
True False False
In this another example, we are seeing of all numbers in list1 are odd and by using all() function, if they are odd then we will return True otherwise False.