为了
test1在函数内部进行修改,您需要将其定义
test1为全局变量,例如:
test1 = 0def testFunc(): global test1 test1 += 1testFunc()
但是,如果只需要读取全局变量,则可以不使用关键字进行打印
global,就像这样:
test1 = 0def testFunc(): print test1 testFunc()
但是,每当需要修改全局变量时,都必须使用关键字
global。

为了
test1在函数内部进行修改,您需要将其定义
test1为全局变量,例如:
test1 = 0def testFunc(): global test1 test1 += 1testFunc()
但是,如果只需要读取全局变量,则可以不使用关键字进行打印
global,就像这样:
test1 = 0def testFunc(): print test1 testFunc()
但是,每当需要修改全局变量时,都必须使用关键字
global。