any(iterable)
return true if any element of the iterable is true. if the iterable is empty, return false. equivalent to:
def any(iterable): for element in iterable: if element: return true return false
说明:
1. 接受一个可迭代器对象为参数,当参数为空或者不为可迭代器对象是报错
>>> any(2) #传入数值报错 traceback (most recent call last): file "<pyshell#0>", line 1, in <module> any(2) typeerror: 'int' object is not iterable
2. 如果可迭代对象中其中一个元素的逻辑值为true时,返回true,全部值均为false时返回false
>>> any([0,1,2]) #列表元素有一个为true,则返回true true >>> any([0,0]) #列表元素全部为false,则返回false false
3. 如果可迭代对象为空(元素个数为0),返回false
>>> any([]) #空列表 false >>> any({}) #空字典 false >>>
以上就是python内置any函数详细介绍的详细内容。
