python tutorial - Python Any | Any & All in Python - learn python - python programming




Any and All are two built ins provided in python used for successive And/Or.

 python any operator

Learn Python - Python tutorial - python any operator - Python examples - Python programs

Any

  • Returns true if any of the items is True. It returns False if empty or all are false. Any can be thought of as a sequence of OR operations on the provided iterables.
  • It short circuit the execution i.e. stop the execution as soon as the result is known.
advanced python act

Syntax : any(list of iterables)

# Since all are false, false is returned
print (any([False, False, False, False]))
 
# Here the method will short-circuit at the
# second item (True) and will return True.
print (any([False, True, False, False]))
 
# Here the method will short-circuit at the
# first (True) and will return True.
print (any([True, False, False, False]))

python tutorial - Output :

False
True
True

 

All

Returns true if all of the items are True (or if the iterable is empty). All can be thought of as a sequence of AND operations on the provided iterables. It also short circuit the execution i.e. stop the execution as soon as the result is known.

Syntax : all(list of iterables)

# Here all the iterables are True so all
# will return True and the same will be printed
print (all([True, True, True, True]))
 
# Here the method will short-circuit at the 
# first item (False) and will return False.
print (all([False, True, True, False]))
 
# This statement will return False, as no
# True is found in the iterables
print (all([False, False, False]))

python tutorial - Output :

True
False
False

Truth table :-

any all in python


Wikitechy tutorial site provides you all the learn python , online python programming course python programming class online , python coding for dummies , python programming classes online , online training python , online python training , python programming online course , python training classes

Related Searches to Any & All in Python