I am a novice in Python and wondering the situation below.
x = 1
def func():
print(x)
x = 2
return x
So I got the UnboundLocalError: local variable 'x' referenced before assignment. But if I right understand - Python read and execute code row by row. So in first statement inside function "print(x)" it must just relay global variable x which eq. 1, but instead I got the error. Please explain, I think it simple.