Python all() function

Updated on Jan 07, 2020


The all() function tests whether all items in the iterable evaluates to True or not. It accepts an iterable and returns True if all the item is true, otherwise, it returns False.

Its syntax is as follows:

all(iterable) -> boolean

Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
>>>
>>> all(['alpha', 'beta', ''])
False
>>>
>>> 
>>> all(['one', 'two', 'three'])
True
>>> 
>>> 
>>> all([])
True
>>>
>>>
>>> gen = (i for i in ['0', (), {}, 51, 89]) # generator
>>> 
>>> 
>>> all(gen)
False
>>>

Try it out:

print(all(['alpha', 'beta', '']))

print(all(['one', 'two', 'three']))

print(all([]))

gen = (i for i in ['0', (), {}, 51, 89]) # generator

print(all(gen))



Other Tutorials (Sponsors)