今天在Leetcode做题的时候,发现讨论区有人的代码出现使用了any()函数,查资料过程中,发现了还有一个all(),对这两个函数简单的对比总结一下.
any(..)
从python doc中得到如下图所示解释:

其意思是对于可迭代对象中有任意一个不为False的时候,返回True,如果可迭代对象为空的话,返回False
示例

all(..)
从python doc中得到下图所示解释:

意思是对于可迭代对象中所有值都为True的情况下返回True,如果当可迭代对象为空的时候,也返回True
示例
