码迷,mamicode.com
首页 > 编程语言 > 详细

python内置函数每日一学 -- all()

时间:2018-07-09 21:32:38      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:--   iter   列表   存在   style   utils   strong   实例   nbsp   

all(iterable)

官方文档解释:

 

Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to:

1 def all(iterable):
2     for element in iterable:
3         if not element:
4             return False
5     return True

详解:

如果iterable中存在元素为0、‘‘、False,all(iterable)返回False,否则返回True

注意:

空元组、空列表返回值为True

实例:

1 print(all([1,2,3,4,5]))                    # True
2 print(all([‘a‘,‘‘,‘c‘,3,4]))              # False
3 print(all([1,0,2,3,4]))                    # False
4 print(all((‘a‘,‘b‘,‘c‘,‘d‘,‘e‘)))        # True
5 print(all((‘a‘,‘‘,‘c‘,‘d‘,‘e‘)))         # False
6 print(all((‘a‘,‘b‘,0,‘d‘,‘e‘)))           # False
7 print(all([]))                              # True
8 print(all(()))                              # True
9 print(all([False,1,2,3]))                  # False

 

python内置函数每日一学 -- all()

标签:--   iter   列表   存在   style   utils   strong   实例   nbsp   

原文地址:https://www.cnblogs.com/YD2018/p/9285978.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!