英文文档:

all(iterable)

Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to:

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

  判断可迭代对象的每个元素都是 True 值

说明:

1. 接受一个可迭代器对象为参数,当参数为空或者不为可迭代器对象是报错

>>> all(2) #传入数值报错
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
all(2)
TypeError: 'int' object is not iterable

2. 如果可迭代对象中每个元素的逻辑值均为True时,返回True,否则返回False

>>> all([1,2]) #列表中每个元素逻辑值均为True,返回True
True
>>> all([0,1,2]) #列表中0的逻辑值为False,返回False
False

3. 如果可迭代对象为空(元素个数为0),返回True

>>> all(()) #空元组
True
>>> all({}) #空字典
True

Python内置函数(32)——all的更多相关文章

  1. Python内置函数(32)——input

    英文文档: input([prompt]) If the prompt argument is present, it is written to standard output without a ...

  2. python内置函数详细介绍

    知识内容: 1.python内置函数简介 2.python内置函数详细介绍 一.python内置函数简介 python中有很多内置函数,实现了一些基本功能,内置函数的官方介绍文档:    https: ...

  3. Python学习:6.python内置函数

    Python内置函数 python内置函数,是随着python解释器运行而创建的函数,不需要重新定义,可以直接调用,那python的内置函数有哪些呢,接下来我们就了解一下python的内置函数,这些内 ...

  4. Python内置函数和内置常量

    Python内置函数 1.abs(x) 返回一个数的绝对值.实参可以是整数或浮点数.如果实参是一个复数,返回它的模. 2.all(iterable) 如果 iterable 的所有元素为真(或迭代器为 ...

  5. Python | 内置函数(BIF)

    Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...

  6. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  7. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  8. Python基础篇【第2篇】: Python内置函数(一)

    Python内置函数 lambda lambda表达式相当于函数体为单个return语句的普通函数的匿名函数.请注意,lambda语法并没有使用return关键字.开发者可以在任何可以使用函数引用的位 ...

  9. [python基础知识]python内置函数map/reduce/filter

    python内置函数map/reduce/filter 这三个函数用的顺手了,很cool. filter()函数:filter函数相当于过滤,调用一个bool_func(只返回bool类型数据的方法) ...

随机推荐

  1. Several ports (8005, 8080, 8009)被占用

    启动Tomcat服务器报错: Several ports (8005, 8080, 8009) required by Tomcat v5.5 Server at localhost are alre ...

  2. php 后端跨域请求

    header("Access-Control-Allow-Origin: http://a.com"); // 允许a.com发起的跨域请求 //如果需要设置允许所有域名发起的跨域 ...

  3. APIcloud 移动端常用事件

    1.监听按键事件 返回键 api.addEventListener({ name:'keyback' }, function(ret, err){ if( ret ){ alert( JSON.str ...

  4. curl post请求总是返回417错误

    在进行post请求的时候, curl总是返回417错误 在使用curl做POST的时候, 当要POST的数据大于1024字节的时候, curl并不会直接就发起POST请求, 而是会分为俩步. 发送一个 ...

  5. springMvc(一)

    SpringMvc 1. 核心:DispatcherServlet 1.1作用:负责拦截请求并分派给相应的处理器处理 1.2配置DispatcherServlet(web.xml) 2.配置处理器映射 ...

  6. Spring data Redis

    http://www.cnblogs.com/tankaixiong/p/3660075.html http://www.aboutyun.com/thread-20755-1-1.html

  7. poj 2503 查字典

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  8. Hibernate学习(2)- hibernate.cfg.xml详解

    1:主配置文件主要分为三部分: 注意:通常情况下,一个session-factory节点代表一个数据库: 1.1:第一部分 数据库连接部分,注意"hibernate.connection.d ...

  9. Java多线程:synchronized关键字和Lock

    一.synchronized synchronized关键字可以用于声明方法,也可以用来声明代码块,下面分别看一下具体的场景(摘抄自<大型网站系统与Java中间件实践>) 案例一:其中fo ...

  10. RPC原理解析

    1.RPC原理解析 1.1 什么是RPC RPC(Remote Procedure Call Protocol) --远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络 ...