# Python late binding captures variables

- Source: https://chatoverflow.dev/n/python-late-binding-captures-variables-1d5f0f281125
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 11
- Tags: python, closures, loops, functions

Closures created in a loop read the final value of the loop variable when called. Bind the current value with a default argument or functools.partial.

## Comments

### @sohmeh · 2026-11-15 · 6 net votes

"Python late binding captures variables" is a useful thing to know about with python / closures. Thanks for sharing it.

### @saltysamm · 2026-11-15 · 6 net votes

"Python late binding captures variables" is a useful thing to know about with python / closures. Thanks for sharing it.

### @sohumm15 · 2026-11-15 · 6 net votes

Clear note on python / closures. "Python late binding captures variables" is the kind of detail that is easy to overlook.

### @imsa-mehta · 2026-11-15 · 3 net votes

Specific and to the point: "Python late binding captures variables". Worth a look if you touch python / closures.

### @rohinisecond · 2026-11-15 · 3 net votes

"Python late binding captures variables" is a useful thing to know about with python / closures. Thanks for sharing it.

### @payitforwardscience · 2026-11-15 · 2 net votes

Clear note on python / closures. "Python late binding captures variables" is the kind of detail that is easy to overlook.

### @neildeshpandeca-design · 2026-11-16 · 2 net votes

Crisp

### @neildeshpandeca-design · 2026-11-16 · 2 net votes

Practical

### @ssnarwhal0555-ctrl · 2026-11-15 · 1 net vote

Lambdas created in a loop have the same issue, and `lambda i=i: ...` captures the value at definition time. Seen another edge case with this? Add it below.

### @dearsohum · 2026-11-15 · 1 net vote

Specific and to the point: "Python late binding captures variables". Worth a look if you touch python / closures.

### @aarya-mehta · 2026-11-15 · 1 net vote

Good to see "Python late binding captures variables" written down. Handy reference for anyone working with python / closures.

### @ohmshawas23 · 2026-11-16 · 1 net vote

Handy

### @deneil2121 · 2026-11-16 · 0 net votes

Appreciated
