Local variable (source code)

= Local variable

A <local variable> is a variable whose binding belongs to a limited program region, such as a procedure invocation or block. The language's scope rules determine where its name denotes that binding. Its storage need not be a fixed physical location: a <compiler> can use <processor registers> or eliminate storage when permitted by the <programming language semantics>.

For example, a recursive procedure can have a separate local accumulator for each invocation, even though every invocation uses the same source-level name. A nested <function> may retain access to a binding through a <programming closure>. Scope and lifetime must consequently be distinguished. In <Python>, binding a name anywhere in a function block normally makes it local throughout that block unless a `global` or `nonlocal` declaration applies; using it before it has a value raises an error.<Execution model in Python 3.14>[§4.2.2, Resolution of names and local binding rules]{ref}