我有两个文件-
foo1.py -
a = 0;
b = {};
def f():
global a;
print "foo1: start a -",a;
a = 10;
print "foo1 changed a to :",a;
global b;
print "foo1: start b - ",b;
b['me'] = 'fool';
print "foo1 changed b to :",b;
foo2.py -
from foo1 import *
print "foo2 a before f:", a
print "foo2 b before f:", b
f();
print "foo2 a after f:",a
print "foo2 b after f:",b
当我运行 python foo2.py 时,我看到了这个 -
foo2 a before f: 0
foo2 b before f: {} <br/>
foo1: start a - 0
foo1 changed a to : 10
foo1: start b - {}
foo1 changed b to : {'me': 'fool'}
foo2 a after f: 0 // **Doesn't change**
foo2 b after f: {'me': 'fool'} // **Changes**
有人可以解释一下吗?