我对具有全局功能的词典的行为感到困惑。在下面的例子中,为什么第一个案例打印{' abc':}}而第二个案例打印{' abc':456}?我正在使用python 2.7。
第一个例子:
def foo():
test_dict = {}
bar()
def bar():
test_dict['abc'] = 123
test_dict = {'abc':456}
foo()
print test_dict
第二个例子:
test_dict = {'abc':456}
def foo():
test_dict = {}
test_dict['abc'] = 123
foo()
print test_dict