【发布时间】:2019-01-11 05:29:55
【问题描述】:
test.py
x = 10; # global variable
def func1():
print(x); # prints 10
def func2()
x = x + 1; # IDE shows error: "Unresolved reference of x(RHS of expression)
def func3()
global x;
x = x + 1; # This works
当 x 具有全局范围时,为什么 func2() 不允许我修改它的值,尽管它可以在 func1() 中看到。为什么它需要像 func3() 一样明确提及“全局”关键字?
【问题讨论】:
标签: python