- Learn Python by Building Data Science Applications
- Philipp Kats David Katz
- 100字
- 2021-06-24 13:06:03
The all and any functions
all and any both take an array as their input and are logical expansions of & and | for more than two variables. Essentially, they are equal to repeating & or | for all the elements of the array. Here is an example:
>>> all((True, False, True))
False
>>> any((True, False, False))
True
In the first case, the function returns False, as there is at least one False instance in the iterable. In the second case, there is at least one True instance, so that function returns True as well.