Discuss / Python / 解答

解答

Topic source

冲天魔王

#1 Created at ... [Delete] [Delete and Lock User]
在此插入代码

def count(): def f(j): def g(): return j*j return g fs = [] for i in range(1, 4): fs.append(f(i))

        # f(i)立刻被执行,因此i的当前值被传入f()
    return fs

f1=count() print(f1)

[<function count.<locals>.f.<locals>.g at 0x01F31078>, <function count.<locals>.f.<locals>.g at 0x01F310C0>, <function count.<locals>.f.<locals>.g at 0x01F31108>]

在这里打印f1会发现有3个函数应为python函数可以返回多个值,应为一个List吧

print(f10)

调用


  • 1

Reply