MemotivaFunctions and arguments

What is the late binding closure pitfall?

Functions and arguments

Audio flashcard · 0:16

Nortren·

What is the late binding closure pitfall?

0:16

When a closure captures a variable from an enclosing loop, it captures the variable name, not the value at the time of definition. By the time the closure is called, the variable holds the final value of the loop. The fix is to capture the value at definition time, often by using a default argument.
docs.python.org