英文文档:
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. 接受一个可迭代器对象为参数,当参数为空或者不为可迭代器对象是报错
立即学习“Python免费学习笔记(深入)”;
>>> any(2) #传入数值报错Traceback (most recent call last): File "", line 1, in any(2)TypeError: 'int' object is not iterable
登录后复制
2. 如果可迭代对象中其中一个元素的逻辑值为True时,返回True,全部值均为False时返回False
>>> any([0,1,2]) #列表元素有一个为True,则返回TrueTrue>>> any([0,0]) #列表元素全部为False,则返回FalseFalse
登录后复制
3. 如果可迭代对象为空(元素个数为0),返回False
>>> any([]) #空列表False>>> any({}) #空字典False>>>
登录后复制
以上就是Python内置any函数详细介绍的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2275813.html