It is used when you want to check that all the elements in the list have values. For example, when you first initialize the list as [[], [], []], do some processing, and then check that all the elements have values.
all(iterable) Built-in function all This function returns True if all the elements of iterable are true True is other than 0 for numbers, other than'' for letters, other than [] for lists, etc ... So what I'm doing inside is probably like this
all.py
def all(iterable):
for x in iterable:
if not x: return False
else: return True
any(iterable) Built-in function any This function returns True if even one element of iterable is true What I'm doing inside
any.py
def any(iterable):
for x in iterable:
if x: return True
else: return False
easy_example.
>>> a = [1,2,3,4,5]
>>> all(a)
True
>>> any(a)
True
>>> a = [0,1,0,0,0]
>>> all(a)
False
>>> any(a)
True
>>> a = [0,0,0,0,0]
>>> all(a)
False
>>> any(a)
False
all (): Returns True if each element of iterable is true. any (): Returns True if at least one element of iterable is true.
Recommended Posts