test=4
def sum1(var):
print("in function, test",test)
var+=1
test=7
print("in function, var",var)
print("in function, test",test)
sum1(5)
print(test)
I'm trying to understand global and local variable, so I try it this way: a global and a local variable that has same names (I know we normally don't do that).
In this program it has an "UnboundLocalError: local variable 'test' referenced before assignment" I am wondering why the first print() that prints the test cannot be printed out? Why wouldn't it call the global "test"?