any(my_iterable)
my_iterable : iterable inputElements of the iterable | any() Output | all() Output |
---|---|---|
All are True | True | True |
All are False | False | False |
One value is True ( Others False) | True | False |
One value is False ( Others True) | True | False |
Empty | False | True |
list=[]
print(any(list)) # False
list=[0,False]
print(any(list)) # False
list=[False,True]
print(any(list)) # True
url='plus2net.com'
print(any(url)) # True
url='False'
print(any(url)) # True
We will use Dictionarymy_dict={0:'A',1:'B'}
print(any(my_dict)) # True
my_dict={0:'A',0:'B'}
print(any(my_dict)) # False
my_dict={0:True,0:False}
print(any(my_dict)) # False
my_dict={1:True,2:False}
print(any(my_dict)) # True
We will use tuplemy_tuple=(True,1,12)
print(any(my_tuple)) # True
my_tuple=(True,0)
print(any(my_tuple)) # True
my_tuple=(0,0)
print(any(my_tuple)) # False
my_tuple=(0,1)
print(any(my_tuple)) # True
Using if else
a,b,c=0,0,1
if any((a,b,c)):
print("Yes")
else:
print("No")
all() Iterator
in and not in Membership operators