内部函数捕获外部变量?

Inner Functions captures outside variable?

def outer_function(some_function):
    def inner_function(arg):
        print arg
    return inner_function

def function_2(a):
    return a

x = outer_function(function_2)
x(3)

我的问题是 inner_function 如何捕获我传递给 x 的参数,即 3。内部函数如何捕获外部函数参数?

内部函数未捕获外部函数参数。

x = outer_function(function_2)

x 现在是对 inner_function 的引用,它接受一个参数并打印它。

x(3)

这与 inner_function(3) 相同,后者仅打印 3,因此打印 3。