what is any in python code example
Example 1: any in python
The any() function takes an iterable (list, string, dictionary etc.) in Python.
The any() function returns the boolean value:
True if at least one element of an iterable is true
False if all elements are false or if an iterable is empty
Example:
some_list = [1, 2, 3]
print(any(some_list)) # True
another_list = []
print(any(another_list)) # False
Example 2: any function in python
s = input()
print(any(i.isalnum() for i in s))
print(any(i.isalpha() for i in s))
print(any(i.isdigit() for i in s))
print(any(i.islower() for i in s))
print(any(i.isupper() for i in s))
Example 3: any and all in python3
# 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]))