小白教程
所有教程
关于
Search
172.69.6.176
172.69.6.176
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python func all”的源代码
本页内容
上一节:
Python_func_setattr
下一节:
Python_func_dir
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:all()}}[[Category:python3 built in functions|6]] = Python all() 函数 = [[python built in functions|Python 内置函数]] == 描述 == all() 函数用于判断给定的可迭代参数 iterable 中的所有元素是否都为 TRUE,如果是返回 True,否则返回 False。 元素除了是 0、空、None、False 外都算 True。 函数等价于: <sample title="" desc="" lang="python" hererun="1"> def all(iterable): for element in iterable: if not element: return False return True </sample> Python 2.5 以上版本可用。 === 语法 === 以下是 all() 方法的语法: <sample title="" desc="" lang="python" hererun="1"> all(iterable) </sample> === 参数 === * iterable -- 元组或列表。 === 返回值 === 如果iterable的所有元素不为0、''、False或者iterable为空,all(iterable)返回True,否则返回False; '''注意:'''空元组、空列表返回值为True,这里要特别注意。 以下展示了使用 all() 方法的实例: <sample title="" desc="" lang="python" hererun="1"> >>> all(['a', 'b', 'c', 'd']) # 列表list,元素都不为空或0 True >>> all(['a', 'b', '', 'd']) # 列表list,存在一个为空的元素 False >>> all([0, 1,2, 3]) # 列表list,存在一个为0的元素 False >>> all(('a', 'b', 'c', 'd')) # 元组tuple,元素都不为空或0 True >>> all(('a', 'b', '', 'd')) # 元组tuple,存在一个为空的元素 False >>> all((0, 1, 2, 3)) # 元组tuple,存在一个为0的元素 False >>> all([]) # 空列表 True >>> all(()) # 空元组 True </sample> [[python built in functions|Python 内置函数]]
返回至“
Python func all
”。
上一节:
Python_func_setattr
下一节:
Python_func_dir