zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    bzoj 1503
    bzoj 1193 贪心+bfs
    bzoj 1798 线段树
    Codeforces 804D Expected diameter of a tree
    bzoj 1208
    bzoj 3224
    HDU 5115 区间dp
    hihocoder #1162 矩阵加速dp
    分块入门
    bzoj 1036 树链剖分
  • 原文地址:https://www.cnblogs.com/lpgit/p/9285978.html
Copyright © 2011-2022 走看看