# of course, the ... are not part of the actual code
some_var = {"key1":"value1" ... "keyN":"valueN"}
def some_func():
v = some_var["key1"]
代码可以正常运行,但我能够直接访问
some_var
这一事实令我感到困惑。上一次我写Python代码时,我记得必须像这样编写some_func
:def some_func():
global some_var
v = some_var["key1"]
我正在使用Windows 7电脑上的Python 2.7.1版本。2.7版本中是否有任何更改,可以实现这一点?
global
关键字。 - phihagglobal
关键字。 - Peter C