any() function in Python with a callback

前端 未结 8 1144
别那么骄傲
别那么骄傲 2020-12-13 01:34

The Python standard library defines an any() function that

Return True if any element of the iterable is true. If the iterable is empty, return False.

8条回答
  •  无人及你
    2020-12-13 02:07

    Slight improvement to Antoine P's answer

    >>> any(type(e) is int for e in [1,2,'joe'])
    True
    

    For all()

    >>> all(type(e) is int for e in [1,2,'joe'])
    False
    

提交回复
热议问题