Any and All are two built ins provided in python used for successive And/Or.
Returns true if any of the items is True. It 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)
False True True
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)
True False False
See whether at least one number is divisible by 5 in list 1=> True
See whether all numbers in list1 are odd => True
Truth table :-
This article is contributed by Mayank Rawat .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python - Test if all rows contain any common element with other Matrix
- Print first m multiples of n without using any loop in Python
- Python | Sort Tuples in Increasing Order by any key
- Python | Find current weather of any city using openweathermap API
- Python | Pandas Series/Dataframe.any()
- Python | Pandas Index.any()
- Python | Remove tuple from list of tuples if not containing any character
- Python | Check if two lists have any element in common
- Python | Check if suffix matches with any string in given list
- Python | Numpy numpy.matrix.any()
- Numpy recarray.any() function | Python
- Python | Check if string ends with any string in given list
- Numpy MaskedArray.any() function | Python
- Python | Test if any list element returns true for condition
- Python | Check if any element occurs n times in given list
- Python | Check if any element in list satisfies a condition
- Select any row from a Dataframe in Pandas | Python
- Python | Check if tuple has any None value
- Python | Check if any String is empty in list
- Python - Check if string starts with any element in list
Improved By : pritam_pranjay