如果是對全局變量的修改用:global
如果是對閉包中函數的局部變量的修改請用:nonlocal
x = 300
def test1():
x = 200
def test2():
nonlocal x
print("----1----x=%d" % x)
x = 100
print("----2----x=%d" % x)
return test2
t1 = test1()
t1()
如果是對全局變量的修改用:global
如果是對閉包中函數的局部變量的修改請用:nonlocal
x = 300
def test1():
x = 200
def test2():
nonlocal x
print("----1----x=%d" % x)
x = 100
print("----2----x=%d" % x)
return test2
t1 = test1()
t1()
1.一切皆對象: 動態語言與靜態語言的區別: python面向對象更加徹底。 python中一切皆對象。函數,類,異常等等都是對象。 可以動態修