python内置函数每日一学 -- all()
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