闭包的应用 先看代码
def test(a,b): def test_in(x): print(a*x+b) return test_in line1 = test(1,1) line1(0)
test函数就是典型的闭包应用 test传入了两个外部函数变量 返回了内部函数的引用 然后调用 line1(0) 代表传入了x的纸 最后的输出结果 就是1
闭包的应用 先看代码
def test(a,b): def test_in(x): print(a*x+b) return test_in line1 = test(1,1) line1(0)
test函数就是典型的闭包应用 test传入了两个外部函数变量 返回了内部函数的引用 然后调用 line1(0) 代表传入了x的纸 最后的输出结果 就是1