flist = []
for i in range(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print(f(2))
The above code prints 4 4 4
I understand that this is python closure and late binding concept.
Under the hood - the function is an object. Since the last value of i gets assigned to every function, does this mean that in python the function is a mutable object and that the function's local variable are its attributes?