Python function-any () any (iterable)
Version: This function is applicable to Python 2.5 and later versions. it is compatible with Python 3.
Note: If no iterable element is 0, '', False, all (iterable), True is returned. If iterable is null, False is returned. Functions are equivalent:
Note that the difference between this function and all () is that any is arbitrary, and all is all. We recommend that you compare and learn the differences and relationships between the two. For details, refer to "python functions daily lecture-all ()".
Def any (iterable ):
For element in iterable:
If element:
Return False
Return True
Iterable: iteratable object;
Example:
>>> Any (['A', 'B', 'C', 'D']) # list, all elements are not empty or 0
True
>>> Any (['A', 'B', '', 'D']) # list, with an empty element
True
>>> Any ([0, '', False]) # list. all elements are 0,'', and false.
False
>>> Any ('A', 'B', 'C', 'D') # tuple, the elements are not empty or 0
True
>>> Any ('A', 'B', '', 'd) # tuple, an empty element
True
>>> Any (0, '', False) # tuple, all elements are 0,'', false
False
>>> Any ([]) # Empty list
False
>>> Any () # empty tuples
False