This should be a closure, we can change this function
def f(k):
def g():
print(k)
return g
a = 1
x = f(a)
a = 2
x()
# 打印出
# 1
Would this make it easier to understand? You can read this blog, which explains the principle of closure at the bottom level. Detailed explanation of Python closures
This should be a closure, we can change this function
Would this make it easier to understand?
You can read this blog, which explains the principle of closure at the bottom level. Detailed explanation of Python closures