热线电话:13121318867

登录
2019-01-24 阅读量: 780
python中的any函数的作用是什么?

如果可迭代的对象中任何一个元素为 true 的话返回 True 。如果可迭代的对象为空则返回 False 。

_any = False
for item in iterable:
if item:
_any = True
break
if _any:
# do stuff

更容易的写法:

if any(iterable):
# do stuff
0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子