If we run this code
a = 1
def foo():
b = a + 2
print(b)
foo()
it works.
But if we run this code
a = 1
def foo():
b = a + 2
print(b)
a = a + 4
print(a)
foo()
it doesn't work.
Question:
why in the first example b = a + 2
works without errors but in the second example the same line of code b = a + 2
is broken?
why if there is no reassignment of a
we can get a
from a global scope but if there is a reassignment we don't have an access to a
even if new local a
doesn't even exist yet (because the reassignment isn't finished).