闭包
书上源代码这样滴def func(x):
def funcc(y):
return x*y
return funcc
temp = func(7)
print(temp(8))
我就好奇是先给x赋值还是y赋值,所以做了小小改动
def func(x):
print("x:", x)
def funcc(y):
print("y:", y)
return x*y
return funcc
temp = func(7)
print(temp(8))
结果为x: 7 y: 8 56
可得先给x赋值再到y
页:
[1]