Everything and everything in Python

Python Methods and Functions

Any

Returns true if any of the elements is True. Returns False if empty or all is false. Anyone can be thought of as a sequence of OR operations on the provided iterations. 
This closes the execution, i.e. stops execution as soon as the result is known.

Syntax: any (list of iterations)

# Since everything is false, false is returned

print ( any ([ False , False , False , False ]))

 
# Here the method will short-circuit to
# Second item (True) and return True.

print ( any ([ False , True , False , False ]))

 
# The method will be short-circuited here
# first (True) and will return True.

print ( any ([ True , False , False , False ]))

Output:

 False True 

All

Returns true if all elements are known is True (or if the iteration is empty). All of this can be thought of as a sequence of AND operations on the provided iterations. This also closes the execution, i.e. stops execution as soon as the result is known.

Syntax: all (list of iterations)

# All iterations here are True, so all
# will return True and the same will be printed

print ( all ([ True , True , True , True ]))

 
# The method will be short-circuited here
# first item (False) and returns False.

print ( all ([ False , True , True , False ]))

 
# This statement will return False, since no
# Found true in iterations

print ( all ([ False , False , False ]))

Output:

 True False False 

Truth table: —

This article is contributing to Mayank Rawat If you love Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or post the article [email protected] See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.





Tutorials