A question is about variable scope.
Why next next function2 modifies list l
def function1():
myvar = 1
l = []
def function2():
l.append(3)
function2()
print l
But it gives error "local variable 'myvar' referenced before assignment", if I add next line myvar = 4,
def function1():
myvar = 1
l = []
def function2():
myvar += 4
l.append(3)
function2()
print l
How to modify myvar that is local to function1 within function2 without making myvar belong to the module scope (module global variable)?
References to documentation are appreciated!