Function Name:
all(iterableObject)
Function Overview:
The all() function checks whether a python iterable object has all of its elements evaluate to True. For example, a python list object with some of its elements as None will make the all() method return False;
If the iterable object is empty the all() function will return True;
The all() method will return true if the iterable object is empty or all the elements of the iterable object evaluate to True;
Parameters:
iterableObject - A python iterator object
Python Example Program using all() function:
# An iterable with some members as None to be checked list = [5,7,3,None,15,12,11,None] print("Return value of all() function when one or more elements evalaute to False:{}".format(all(list)))
# An empty iterable object emptyList = [] print("Return value of all() function when the iterable object is empty:{}".format(all(emptyList)))
# An empty iterable object validElemList = [10,20,30,40,50,60] print("Return value of all() function when all the elements evaluate to True:{}".format(all(validElemList))) |
Output of Python Example Program that uses the all() function:
Return value of all() function when one or more elements evalaute to False:False Return value of all() function when the iterable object is empty:True Return value of all() function when all the elements evaluate to True:True |