Python 3
에 함수 개체 목록을 추가 할 때 순서가 손실 될 수 있습니까?Python 목록의 이상한 동작
나의 이해는 파이썬 목록이 주문하고 실제로
numbers = []
for i in range(10):
numbers.append(i)
print(numbers)
수익률이 예상대로 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
을 실행하는 것이 었습니다.
나는 기능이 MWE에서처럼, 그러나 개체를 추가하는 경우 :
functions = []
for k in range(10):
def test():
print('This is the %i th function.' %k)
functions.append(test)
및 전화 functions[2]()
내가 This is the 9 th function.
이
누군가가이 이상한 행동의 의미를 만들 수거야?
[늦은 바인딩 클로저] (http://docs.python-guide.org/en/latest/writing/gotchas/#late-binding-closures) –