any(iterable)
version: This function is suitable for version 2.5 or above and is compatible with python3 version.
Explanation: If any element of iterable is not 0, '', False, all(iterable) returns True. If iterable is empty, returns False. The function is equivalent to:
Note the difference between this function and the all() function, any means any, and all means all. It is recommended to compare and study the differences and connections between the two. You can refer to "Daily Lecture on Python Functions - all()"
def any(iterable):
for element in iterable:
if element:
return False
return True
Parameter iterable: Iterable object;
Example:
>>> any(['a', 'b', 'c', 'd']) #List list, none of the elements are Empty or 0
True
>>> any(['a', 'b', '', 'd']) #List list, there is an empty element
True
>>> any( [0, '', False]) #List list, all elements are 0,'',false
False
>>> any(('a', 'b', 'c', 'd' )) #Tuple tuple, none of the elements is empty or 0
True
>>> any(('a', 'b', '', 'd')) #Tuple tuple, one of the elements is empty The elements of
True
>>> any((0, '', False)) #Tuple tuple, the elements are all 0,'', false
False
>>> any([ ]) # Empty list
False
>>> any(()) # Empty tuple
False