码迷,mamicode.com
首页 > 其他好文 > 详细

all & any

时间:2016-12-05 11:52:29      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:turn   pytho   python   rgs   rabl   value   highlight   war   ret   

def all(*args, **kwargs):
    """
    Return True if bool(x) is True for all values x in the iterable.
    
    If the iterable is empty, return True.
    """

例:

print(all([1, 2, 3, 0]))   # False
print(all([1, 2, 3]))      # True
print(all([1, 2, 3, ‘‘]))  # False
print(all(‘‘))             # True

any

def any(*args, **kwargs): 
    """
    Return True if bool(x) is True for any x in the iterable.
    
    If the iterable is empty, return False.
    """

例:

print(any([0, ‘‘]))        # False
print(any([1, 2, 3]))      # True
print(any([1, 2, 3, ‘‘]))  # True
print(any(‘‘))             # False

  

all & any

标签:turn   pytho   python   rgs   rabl   value   highlight   war   ret   

原文地址:http://www.cnblogs.com/lcgsmile/p/6133190.html

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