In this code:
> python
>>> a = []
>>> for i in range(2):
... def printer():
... print i
... a.append(printer)
...
>>> a
[<function printer at 0x01EDE330>, <function printer at 0x01EDE2F0>]
>>> a[0]()
1
>>> a[1]()
1
>>>
>>> a[0] == a[1]
False
it appears that I made two different functions, and stored them in the array a[]
.
I don't understand why the functions appear to be different, but the result of each function is not. I would have thought either the functions would be the same (IE the second iteration would redefine the one from the first), or the functions would be different and the result would be different (0 and 1 respectively).
I hoping for and expecting the latter...