I have been using python for more than a year now but I am confused by something in this example:
def mul(x,y): return x*y
def setArg(f,a):
def fx(*x):
return f(*x,a)
return fx
def test1():
mul3=setArg(mul,3)
def test2():
mul=4
def test3():
mul=setArg(mul,3)
def test4():
mu=setArg(mul,3)
mul=mu
running test1 and test2 works fine,but running test3 and test4 give this error:
UnboundLocalError: local variable 'mul' referenced before assignment
Can I only redefine mul inside a testX globally? Why is so in python? using python3.7