Manual
Return True if any element of theiterable is true. If the iterable is empty, returnFalse. Equivalent to:
def any(iterable):
for element in iterable:
if element:
return True
return False
直译
如果序列的任意元素为真则返回True,如果序列为空则返回False。
实例
>>> any([])
False
>>> any({})
False
>>> any('')
False
>>> any(())
False
>>> any([False])
False
>>> any(['Wolegequ', False])
True
NOTE
注意比对all()用法,all指代序列所有元素,any指代序列任意元素,注意比对一下用法:
>>> any(['Wolegequ', False])
True
>>> all(['Wolegequ', False])
False
这种用法类似’and’与’or’
本文详细介绍了Python内置函数any()的使用方法及其与all()的区别。any()用于判断序列中是否存在至少一个元素为真值,若存在则返回True;若序列为空,则返回False。通过多个示例对比了any()与all()的不同之处。
1631

被折叠的 条评论
为什么被折叠?



