Python variables?
Ned Batchelder
ned at nedbatchelder.com
Mon Sep 30 19:47:49 EDT 2013
On 9/30/13 6:37 PM, Ben Finney wrote:
> Ethan Furman <ethan at stoneleaf.us> writes:
>
>> From [Ned Batchelder]'s blog:
>>> Names are Python's variables: they refer to values, and
>>> those values can change (vary) over the course of your
>>> program.
>> This is partially incorrect. If the value referred to by the name is
>> immutable, then it cannot change; perhaps you meant to say that which
>> object the name points to can vary over time?
> I agree. Names are not Python's variables.
>
> If anything in Python is a “variable” as generally understood, it is not
> a name. It is a *binding*, from a reference (a name, or some other
> reference like a list item) to a value.
>
> It is the binding which can change over the course of the program, so
> that is the variable.
>
True, but no one calls the binding the variable. Here is a program:
x = 4
Every one of us is perfectly comfortable talking about the variable x.
Don't get hung up on implementation pedantry. The name x here refers to
4. Later it could refer to "four". The value associated with the name
x changed. x is a variable.
--Ned.
More information about the Python-list
mailing list