Python 中的 all() 和 any()

Python 中的 all() 和 any()

转载请注明出处:https://blog.csdn.net/jpch89/article/details/85119026



1. all()

交互模式下使用 help(all) 查看帮助文档:

>>> help(all)
Help on built-in function all in module builtins:

all(iterable, /)
    Return True if bool(x) is True for all values x in the iterable.
    
    If the iterable is empty, return True.
  • all() 函数接收一个可迭代对象作为参数,不能不传参数调用。
  • 对可迭代对象中的每个元素 x 都进行布尔类型转换 bool(x),如果它们都为 True,那么返回 True,只要有一个为 False,则返回 False
  • 假如可迭代对象为空,返回 True

相当于 x1 and x2 and x3 ... and xn 得到的结果


2. any()

交互模式下使用 help(any) 查看帮助文档:

>>> help(any)
Help on built-in function any in module builtins:

any(iterable, /)
    Return True if bool(x) is True for any x in the iterable.
    
    If the iterable is empty, return False.

  • any() 函数接收一个可迭代对象作为参数,不能不传参数调用。
  • 对可迭代对象中的每个元素 x 都进行布尔类型转换 bool(x),如果它们都为 False,那么返回 False,只要有一个为 True,则返回 True
  • 假如可迭代对象为空,返回 False

相当于 x1 or x2 or x3 ... or xn 得到的结果


完成于 2018.12.27

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值