O'Reilly logo
  • You Wang thinks this is interesting:

to make this sort of code work, we must pass in the current value of the enclosing scope’s variable with a default. Because defaults are evaluated when the nested function is created (not when it’s later called), each remembers its own value for i

From

Cover of Learning Python, 5th Edition

Note

'default argument' is evaluated during creation