any(iterable)

作用:

如果iterable的任何元素不为0、''、False,all(iterable)返回True。如果iterable为空,返回False。

函数等价于:

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

参数iterable:可迭代对象;

实例:

 >>> any(['a', 'b', 'c', 'd'])  #列表list,元素都不为空或0
True
>>> any(['a', 'b', '', 'd']) #列表list,存在一个为空的元素
True
>>> any([0, '', False]) #列表list,元素全为0,'',false
False >>> any(('a', 'b', 'c', 'd')) #元组tuple,元素都不为空或0
True
>>> any(('a', 'b', '', 'd')) #元组tuple,存在一个为空的元素
True
>>> any((0, '', False)) #元组tuple,元素全为0,'',false
False >>> any([]) # 空列表
False
>>> any(()) # 空元组
False

注意:

比较该函数与all()函数的区别,any是任意,而all是全部。建议比较学习两者的区别与联系

最新文章

  1. genymotion安装及问题解决
  2. outscan 一键批量 get struct2 devMode (CNVD-2016-04656)
  3. hdu 4698 - Counting(思路)
  4. 【转】【SEE】基于SSE指令集的程序设计简介
  5. 图-用DFS求连通块- UVa 1103和用BFS求最短路-UVa816。
  6. 【WCF 1】WCF框架宏观了解
  7. CSS 列表 你知道吗
  8. 【JSP】JSP与oracle数据库交互案例
  9. Linux显示版本信息并退出
  10. VC++读取图像RGB值
  11. 【BZOJ】3282: Tree(lct)
  12. win10家庭版升级专业版的两种方法和密钥
  13. discuz 文件模板edit
  14. PHP SFTP应用(二)
  15. php面试题之一——php核心技术
  16. jar包冲突常用的解决方法
  17. linux提权辅助工具(二):linux-exploit-suggester-2.pl
  18. c#之反射(Reflection)
  19. A class for dynamic icons in Windows
  20. linux 查看系统当前时间,修改时间

热门文章

  1. four application:geocoder widget
  2. Python的operator.itemgetter函数和sorted函数
  3. Linux服务器注意事项
  4. linux 安装tomcat7
  5. oracle 字典表查询
  6. 使用UNIDAC连接oracle时的参数设置
  7. 解决maven寻找依赖关系失败的问题
  8. 软件体系结构C2风格
  9. UVA 12716 GCD XOR (异或)
  10. rpm卸载软件error preun