我知道之前已经解释过这个问题了,但是我仍然无法弄清楚我的场景,我解释的很简单:
def func1 ():
a = 1
b = 2
print a + b
def func2 ():
c = 3
d = 4
e = a * c
f = b + d
func1()
func2()
Run Code Online (Sandbox Code Playgroud)
当像这样运行时:
$ ./test1.py
3
Traceback (most recent call last):
File "./test1.py", line 18, in <module>
func2()
File "./test1.py", line 14, in func2
e = a * c
NameError: global name 'a' is not defined
Run Code Online (Sandbox Code Playgroud)
简单的问题是,如何更改上面的代码,以便func2存储来自func1的变量?