(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 any() function
Updated on Jan 07, 2020
The any()
function tests whether any item in the iterable evaluates to True
to not. It accepts an iterable and returns True
, if at least one item in the iterable is true, otherwise, it returns False
.
Its syntax is as follows:
any(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 | >>>
>>> any([10, "", "one"])
True
>>>
>>>
>>> any(("", {}))
False
>>>
>>>
>>>
>>> any([])
False
>>>
>>>
>>> gen = (i for i in [5, 0, 0.0, 4]) # generator
>>>
>>> any(gen)
True
>>>
|
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