The “does Python have variables?” debate (was: Pass variable by reference)

Ben Finney ben at benfinney.id.au
Tue May 6 19:55:24 EDT 2014


Ned Batchelder <ned at nedbatchelder.com> writes:

> This meme bugs me so much. Python has variables. They work differently
> than variables in C.

Which is why it's useful to intervene right at the start when someone
comes in with assumptions about “variables”; it's better that they
discard that baggage and learn about reference binding, instead.

> In fact, they work by having names bound to values.

My position is that this concept is sufficiently different to what most
newcomers to Python mean by “variable” (those who have the term at all;
and for those who don't, no need to introduce potentially-confusing
terms) that it's better to avoid that term entirely and immediately use
more-accurate terminology.

> If you want to insist that Python has no variables, you will have to
> also say that neither do Javascript, Ruby, Java, PHP, etc.

I don't know enough Ruby to comment there. For Java, Javascript, PHP,
they *do* have variables that work pretty much as expected by these
newcomers: the variables are declared and exist before a value is
assigned, they have the “box containing a value” conceptual model (as
contrasted with Python's “value with sticky-notes attached” model), the
“how do I pass by reference or by value?” question is meaningful — all
of these are significantly different in Python, so the term “variable”
is useful in those other languages but mostly just a confusing obstacle
in learning Python.

> And if Javascript has no variables, what does the var keyword mean?

Exactly; JavaScript *does* have variables, in the ways Python does not.

-- 
 \        “If you have the facts on your side, pound the facts. If you |
  `\     have the law on your side, pound the law. If you have neither |
_o__)                       on your side, pound the table.” —anonymous |
Ben Finney




More information about the Python-list mailing list