Код: Выделить всё
x = [1,2,3]
test = []
for i in range(3):
def broken_func(a):
return x[i] + a
test.append(broken_func)
print('Test at creation :', test[-1](1), test[-1])
for func in test:
print('Test later :', func(1), func)
Код: Выделить всё
Test at creation : 2
Test at creation : 3
Test at creation : 4
Test later : 4
Test later : 4
Test later : 4
Есть идеи, как исправить код и помочь мне понять, почему он не работает?
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/798 ... -in-python