The “does Python have variables?” debate

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed May 7 20:57:31 EDT 2014


On Wed, 07 May 2014 11:48:15 -0400, Jerry Hill wrote:

> On Wed, May 7, 2014 at 2:18 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Ned Batchelder <ned at nedbatchelder.com>:
>>
>>> Why is "variable" sacrosanct and can only be used to describe C
>>> semantics, but we're OK reusing class, int, and function?
>>
>> The Python language specification calls them variables; the terminology
>> discussion should end there.
> 
> Personally, I found the idea that a python variable is a name + value
> pairing to be useful when learning the language, especially when I was
> struggling with the calling semantics (that is, the differences between
> call-by-value, call-by-reference, and call-by-object).  I think it's
> rather silly for someone to insist that python doesn't have variables. 
> On the other hand, I think it can be useful to point out that python
> variable aren't like C variables, and that thinking of python variables
> as having two parts -- names and values -- really can help people who
> are struggling to learn the language.  I know it certainly helped me.

+1

I was in the same position, and I found that while I saw people talking 
about "name bindings" and similar, the difference never sank in until 
somebody (I forget who) said "Python doesn't have variables, it has name 
bindings". Until then, I was still labouring under the misapprehension 
that my mental model of variables I learned from Pascal (equivalent to 
that of C) applied to Python too. Being exposed to an outrageous claim 
like "Python has no variables" lead me to question my assumptions.

Most of the time, when you're just assigning values to a variable name, 
it's a difference that makes no difference. But at the edges, you run 
into some of the differences:

* If you think that variables are necessarily known at compile-time, 
  then Python has no variables.

* If you think that variables have an address, then Python has no 
  variables.

* If you think of variables as a box inside of which the compiler 
  puts a value, then Python has no variables.

* If you think of id(x) as the identity of the *name* "x" rather
  than the identity of the object bound to "x", that is, if you
  think of id(x) as like a pointer to x, then you are mistaken.




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list