>>> def counter(start_at=0):
... count = [start_at]
... def incr():
... count[0] += 1
... return count[0]
... return incr
...
>>> count = counter(7)
>>> print count()
8
>>> print count()
9
위의 코드는 정상적으로 실행되고 있습니다. 이해 했어. 하지만 아래 코드는 위와 같아야한다고 생각했습니다.코드가 이상합니다.
>>> counter(7)()
8
>>> counter(7)()
8
글쎄, 그것은 print count()처럼 행동하지 않습니다. 왜?
-1 제목, http://msmvps.com/blogs/jon_skeet/archive/2010/08를 참조하시기 바랍니다 /29/writing-the-perfect-question.aspx – reto