Label-Value (was: Re: Inheriting the @ sign from Ruby)

Alex Martelli aleaxit at
Thu Dec 14 03:56:11 EST 2000

"Darren New" <dnew at> wrote in message
news:3A380E4E.8537A0FB at
> Erno Kuusela wrote:
> > | Having
> > |  x = 2 + 2
> > |  print x
> > | result in anything except "4" is probably a *really* bad idea.
> > | AFAIK, only FORTH and really old Fortrans allow this.
> >
> > agreed - but this is not something (sane) a mutable integer object
> > would break.
> Well, X is a variable, and you can already change the value in X.

This _may_ harbor a slight misconception, coming from other languages,
that (in more complex cases) may interfere with optimal understanding
of Python.

There is no value *IN* x.

A variable *REFERS TO* 'a value' (aka 'an object').

The distinction is not very important for immutable values (objects):
although they're not really 'IN' any of the variables (or other
'slots') that REFER TO them, you may still write perfectly good
Python code even if labouring under a misconception that they are.

But as soon as mutable values (objects) enter the picture, then
thinking of values (objects) as being IN variables (or other slots)
brings you nothing but trouble.  It's a good mental model for,
say, C.  It's a terrible one for Python (or, as it happens, Java)...

It's a minor point, but getting into the habit of saying 'changing
what value X refers to' (when you mean peeling the postIt-like
'tag' that we call X, which can be affixed to different objects
at different times), or equivalently 'rebinding X to another value',
can, I think, help avoid certain annoying 'mental slips'...


More information about the Python-list mailing list