python之 all() 和 any()

版权声明:转载请标明出处 https://blog.csdn.net/gymaisyl/article/details/87988108

all():可迭代对象,有一个为假(为空),那么则返回False,全为真,才返回True

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

在这里插入图片描述
在这里插入图片描述

any():接收的可迭代对象,只要有真,则返回True,全为假(全为空),才返回False

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

在这里插入图片描述
在这里插入图片描述

注意:

在这里插入图片描述
返回的结果是True

总结:

all()有假则假,any()有真则真,但不要认为all(iterable)为True,则any就一定为True,一定要知道如果iterable为空,all也会返回True

猜你喜欢

转载自blog.csdn.net/gymaisyl/article/details/87988108
今日推荐