all函数

判断可迭代对象的元素为真(空迭代对象为真)

# 可迭代对象为空则真
print(all(""))
print(all([]))

# 全部元素为真则真,否则为False
print(all([1,2,None]))  # None为False
print(all([1,2,'',3]))  # ''空字符串为False
# 等价函数
def all(iterable):
    for element in iterable:
        if not element:
            return False
    return True

猜你喜欢

转载自www.cnblogs.com/ShuComputerProgram/p/10339361.html
ALL