I don't understand the error in this example. Shouldn't print(b)
print 6
, by the Python LEGB rule? When the interpreter scans f(a)
function in line 2, does it memorize that b = 33
and puts in the memory heap or just remembers the information that b
is a local variable?
b = 6
def f(a):
print(a)
print(b)
b = 33
f(20)
# UnboundLocalError: local variable 'b' referenced before assignment