Python函数-any()
2024-09-01 17:06:46
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是全部。建议比较学习两者的区别与联系
最新文章
- genymotion安装及问题解决
- outscan 一键批量 get struct2 devMode (CNVD-2016-04656)
- hdu 4698 - Counting(思路)
- 【转】【SEE】基于SSE指令集的程序设计简介
- 图-用DFS求连通块- UVa 1103和用BFS求最短路-UVa816。
- 【WCF 1】WCF框架宏观了解
- CSS 列表 你知道吗
- 【JSP】JSP与oracle数据库交互案例
- Linux显示版本信息并退出
- VC++读取图像RGB值
- 【BZOJ】3282: Tree(lct)
- win10家庭版升级专业版的两种方法和密钥
- discuz 文件模板edit
- PHP SFTP应用(二)
- php面试题之一——php核心技术
- jar包冲突常用的解决方法
- linux提权辅助工具(二):linux-exploit-suggester-2.pl
- c#之反射(Reflection)
- A class for dynamic icons in Windows
- linux 查看系统当前时间,修改时间