內(nèi)建函數(shù)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.
當傳入空可迭代對象時返回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.
當傳入空可迭代對象時返回True阴孟,當可迭代對象中有任意一個不為True漆枚,則返回False
示例:
>>> any('123')
True
>>> any([0, 1])
True
>>> any([0, ''])
False
>>> all('123')
True
>>> all([0, 1])
False
>>> all([1, 2])
True