python中的函数any()和all()
2015-04-16 15:12
309 查看
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
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
相关文章推荐
- Python函数any()和all()的用法及区别介绍
- Python内建函数(A) all(iterable) any(iterable)
- python: all & any 函数
- Python常用函数总结一(abs, all, any, bool, chr)
- python中map、any、all函数用法分析
- python内建函数any()和all()
- python函数日积月累 basestring()、any()、all()、callable()、divmod()
- python中的函数any()和all()
- python 中的map any all 函数
- 不曾见过的Python函数——any(),all()
- python any()和all()用法
- python内置函数,abc, all, any, bin, bool, bytes, chr, divmod, eval, hash, help, hex, oct, id, instance,等
- python中的any和all
- [Python]Build-in方法all和any
- python mean、cumsum、cumprod、any、all
- python中any()和all()如何使用
- Python ElementTree的find,findall函数参数
- python any()和all()用法
- python any和all的用法, 可以查找某些字符串是否存在
- Python ElementTree的find,findall函数参数