我想从 b() 调用 var d。但我得到这个错误。我听说你可以拥有我尝试过但没有成功的全局变量。
错误:
Traceback (most recent call last):
File "C:/Users/user2/Desktop/def.py", line 9, in <module>
a()
File "C:/Users/user2/Desktop/def.py", line 3, in a
if d == 0:
NameError: name 'd' is not defined
代码:
def a():
if d == 0:
print(correct)
else:
print (not correct)
def b():
d = 0
a()