all()

all(my_iterable)
my_iterable : iterable input Return boolean value True or False based on this table.

Difference between any() and all()

Elements of the iterable any()
Output
all()
Output
All are TrueTrueTrue
All are FalseFalseFalse
One value is True ( Others False)TrueFalse
One value is False ( Others True)TrueFalse
Empty FalseTrue
Read more on any() here.

Empty List

list=[]
print(all(list)) # True
List
list = [1, 2, 3, 4, 55] 
print(all(list)) # True

All elements are False

list=[0,False]
print(all(list)) # False

One element is True

list=[False,True]
print(all(list))  # False

Using string

url='plus2net.com'
print(all(url))    # True
url='False'
print(all(url))    # True
We will use Dictionary

Output depends on Keys of the Dictionary ( Not Values ). If all one of the key is True then output is True. If all keys are False then output is False.
my_dict={0:'A',1:'B'}
print(all(my_dict)) # False  
my_dict={0:'A',0:'B'}
print(all(my_dict)) # False
my_dict={0:True,0:False}
print(all(my_dict)) # False
my_dict={1:True,2:False}
print(all(my_dict)) # True
We will use tuple
my_tuple=(True,1,12)
print(all(my_tuple)) # True
my_tuple=(True,0)
print(all(my_tuple)) # False
my_tuple=(0,0)
print(all(my_tuple)) # False
my_tuple=(0,1)
print(all(my_tuple)) # False
any() Iterator in and not in Membership operators

Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer