foo = 1
def bar():
print(foo)
foo = 5
This function throws UnboundLocalError: local variable 'foo' referenced before assignment.
My question is, how does the interpreter know that foo
is a local variable in this function, what does the interpreter do before it excutes a function?