小白教程
所有教程
关于
Search
172.69.59.48
172.69.59.48
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python func any”的源代码
本页内容
上一节:
Python_func_slice
下一节:
Python3_func_divmod
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:any()}}[[Category:python3 built in functions|11]] = Python any() 函数 = [[python built in functions|Python 内置函数]] == 描述 == any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False,则返回 False,如果有一个为 True,则返回 True。 元素除了是 0、空、FALSE 外都算 TRUE。 函数等价于: <sample title="" desc="" lang="python" hererun="1"> def any(iterable): for element in iterable: if element: return True return False </sample> Python 2.5 以上版本可用。 === 语法 === 以下是 any() 方法的语法: <sample title="" desc="" lang="python" hererun="1"> any(iterable) </sample> === 参数 === * iterable -- 元组或列表。 === 返回值 === 如果都为空、0、false,则返回false,如果不都为空、0、false,则返回true。 以下展示了使用 any() 方法的实例: <sample title="" desc="" lang="python" hererun="1"> >>>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 </sample> [[python built in functions|Python 内置函数]]
返回至“
Python func any
”。
上一节:
Python_func_slice
下一节:
Python3_func_divmod