I have a simple function called return_funcs
here:
>>> def return_funcs():
... functions = []
... for i in range(4):
... functions.append(lambda: i)
... return functions
And when I use return_funcs
this is what I get:
>>> for func in return_funcs():
... func()
...
3
3
3
I was expecting something like:
1
2
3
Why do I get this unexpected output, and how can I fix it?