Any and All
Posted on Fri 01 September 2017 in any, all, python
Python provides two functions that deal with iterable and return True
or False
depending on which boolean values elements of the sequence evaluate to.
- All
all(iterable)
returns True
if all elements of an iterable are considered as true values
e.g.,
all(l == 'y' for l in 'Python') # Returns False. Not all of the letters are 'y'.
- Any
any(iterable)
returns True
if at least one element of the iterable is a true value
e.g.,
any(l == 't' for l in 'python') # Returns True. Same as: 't' in 'python'