I'm at a loss here. I'm trying to define a function inside a for loop. The function uses a variable defined inside the loop and could look something similar like that :
myFuns = []
for i in range(10):
j = i + 4
def fun(): print(j)
myFuns += [fun]
At the end of this loop, my functions in myFuns are differents, but they do the same thing, as apparently, this is not a new variable j that is passed to fun(), but the reference of j.
I'd be very glad to know how to pass the value of j and not just the reference.
I didn't know that a variable created in a loop could outlived the loop, so this is new territory for me here...