相关疑难解决方法(0)

python any()函数究竟是如何工作的?

在python docs页面中any,any()函数的等效代码如下:

def any(iterable):
    for element in iterable:
        if element:
            return True
    return False
Run Code Online (Sandbox Code Playgroud)

如果以这种形式调用它,这个函数如何知道我想测试哪个元素?

any(x > 0 for x in list)
Run Code Online (Sandbox Code Playgroud)

从函数定义中,我只能看到我传递的是一个可迭代对象.for循环如何知道我正在寻找什么> 0

python

97
推荐指数
5
解决办法
14万
查看次数

标签 统计

python ×1