(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!
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:
Other Tutorials (Sponsors)
This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!
View Comments