下面是代碼:這個函數如何找到另一個變量的值?
def caller(callee):
callee()
def wrapper():
def a():
print v0
for i in range(5):
v0 = i*i
caller(a)
wrapper()
上面的代碼輸出:
0
1
4
9
16
但我不知道如何解決a
變量v0
。我無法找到有關此語言功能的相關python文檔。
下面是一些閱讀材料:https:// realpython。com/blog/python/inner-functions-what-are-they-good-for/ – idjaw
[在創建它們的函數中使用全局變量]的可能副本(// stackoverflow.com/questions/423379/ using-global-variables-in-a-function-other-that-one-that-created-them) – Zizouz212
@ Zizouz212此代碼中沒有全局變量(除函數'wrapper'和'caller'外) 。具體而言,'v0'不是全局的。 –