Python 内建函数 - any(iterable)

    xiaoxiao2021-03-25  67

    Manual直译实例NOTE

    Manual

    Return True if any element of theiterable is true. If the iterable is empty, returnFalse. Equivalent to:

    def any(iterable): for element in iterable: if element: return True return False

    直译

    如果序列的任意元素为真则返回True,如果序列为空则返回False。

    实例

    >>> any([]) False >>> any({}) False >>> any('') False >>> any(()) False >>> any([False]) False >>> any(['Wolegequ', False]) True

    NOTE

    注意比对all()用法,all指代序列所有元素,any指代序列任意元素,注意比对一下用法:

    >>> any(['Wolegequ', False]) True >>> all(['Wolegequ', False]) False

    这种用法类似’and’与’or’

    转载请注明原文地址: https://ju.6miu.com/read-39003.html

    最新回复(0)