What is the late binding closures trap?
Common pitfalls and best practices
Audio flashcard · 0:14Nortren·
What is the late binding closures trap?
0:14
When closures are created in a loop, they capture variable names rather than values. By the time the closures are called, the captured variables hold the final values from the loop. The fix is to capture the value at definition time, often by passing it as a default argument.
docs.python.org