= Program variable
A <program variable> is a named binding or storage abstraction used to supply a value during execution of a <computer program>. Its precise meaning belongs to the <programming language semantics>: some languages describe mutable storage locations, while others emphasize names associated with values. The current <semantic environment> and <program state> determine what an occurrence denotes. A mathematical <variable> and a <program variable> consequently need not obey the same rules.
For example, in <Python>, executing `x = 3` followed by `x = x + 1` first evaluates the right-hand <program expression> using the old binding and then binds `x` to the resulting <integer> 4. This <variable assignment> is a change in the <program state>, not the <equation> $x=x+1$.<python-3-14-documentation/Simple statements, Python 3.14 language reference>[§7.2, Assignment statements, evaluation and identifier targets]{ref}
Binding a second name does not necessarily copy the underlying data. After `a = list()` and `b = a`, executing `b.append(7)` changes the <list> also reached through `a`. By contrast, `b = list()` rebinds only `b`. Distinguishing changes to data from changes to names makes shared mutable structures easier to reason about.<python-3-14-documentation/Simple statements, Python 3.14 language reference>[§7.2, rebinding names versus modifying mutable objects]{ref}
Back to article page