To change test1 inside the function, you will need to define test1 as a global variable, for example:
test1 = 0 def testFunc(): global test1 test1 += 1 testFunc()
However, if you only need to read the global variable, you can print it without using the global , for example:
test1 = 0 def testFunc(): print test1 testFunc()
But whenever you need to change a global variable, you should use the global .
Florin Stingaciu Aug 10 2018-12-12T00: 00Z
source share