注册 登录
编程论坛 Python论坛

python中的append的用法 ,appen(L[i] (x)),不是很明白,求指教

莫珞lili 发布于 2016-10-24 17:15, 4193 次点击
文档里面是这么说明的

list.append(x)
Add an item to the end of the list. Equivalent to a[len(a):] = [x].

但是在自学的时候,看到这么个函数定义
def applyEachTo(L, x):
    result = []
    for i in range(len(L)):
        result.append(L[i](x))
    return result


中间的result.append(L[i](x))不是很明白。整个是这样的

程序代码:
def applyEachTo(L, x):
    result = []
    for i in range(len(L)):
        result.append(L[i](x))
    return result

def square(a):
    return a*a
def halve(a):
    return a/2

def inc(a):
    return a+1
   
a = applyEachTo([inc, square, halve, abs], -3)
2 回复
#2
莫珞lili2016-10-24 17:17
难道说是直接拼接?调用的时候就变成了result.append(lic(x))?这样子?
1