python中又很多好玩的函數,下面說一下內建函數any()和all():
any(...)
any(iterable) -> bool
Return True if bool(x) is True for any x in the iterable.
If the iterable is empty, return False.
以上是python doc中得說明,意思就是當傳入空可迭代對象時返回False,當可迭代對象中有任意一個不爲False,則返回True
all(...)
all(iterable) -> bool
Return True if bool(x) is True for all values x in the iterable.
If the iterable is empty, return True.
以上是python doc中得說明,意思就是當傳入空可迭代對象時返回True,當可迭代對象中有任意一個不爲True,則返回False示例:
>>> any('123')
True
>>> any([0, 1])
True
>>> any([0, ''])
False
>>> all('123')
True
>>> all([0, 1])
False
>>> all([1, 2])
True