Look at this very basic code:
s2 = 'prefixe'
cpt = 1
def test():
cpt += 1
str = "%s%d" % (s2,cpt)
print(str)
test()
I have an error. It says that cpt is read before assignment. It is normal to my opinion because cpt should be declared as a global variable:
s2 = 'prefixe'
cpt = 1
def test():
global cpt
cpt += 1
str = "%s%d" % (s2,cpt)
print(str)
test()
In this case, i have no error and the program works fine.
But, why there is no error for s2 variable ? This variable should be declared as a global variable too ? Why do not i have error ?
Thanks