Python built-in functions (2) -- all, python built-in functions all
English document:
all
(Iterable)
ReturnTrue
If all elements ofIterableAre true (or if the iterable is empty). Equivalent:
def all(iterable): for element in iterable: if not element: return False return True
Note:
1. Accept an iterator object as a parameter. If the parameter is null or not an iterator object, an error is returned.
>>> All (2) # input value error Traceback (most recent call last): File "<pyshell #9>", line 1, in <module> all (2) typeError: 'int' object is not iterable
2. If the logical value of each element in the iteratable object is True, True is returned; otherwise, False is returned.
>>> All ([1, 2]) # returns TrueTrue if the logical value of each element in the list is True. >>> all ([, 2]) # If the logical value of 0 in the list is False, FalseFalse is returned.
3. If the iteratable object is null (the number of elements is 0), True is returned.
>>> All () # null tuples True >>> all ({}) # null dictionary True