我有一个在 while 循环中定义的函数,该函数由我无法控制的代码调用。
在以下示例中,access() 始终返回值 1。为什么?以及如何使 access() 返回最新值?
while True:
g = [1,2,3]
def access():
return g[0]
print(access())
g[0] += 1
lambda 似乎也是如此。我不能让 g 全球化。
我有一个在 while 循环中定义的函数,该函数由我无法控制的代码调用。
在以下示例中,access() 始终返回值 1。为什么?以及如何使 access() 返回最新值?
while True:
g = [1,2,3]
def access():
return g[0]
print(access())
g[0] += 1
lambda 似乎也是如此。我不能让 g 全球化。