Assignment vs. Naming/Binding (was Re: Augmented Assignement )

Terry Reedy tjreedy at home.com
Sun Jul 1 11:44:32 EDT 2001


"David Bolen" <db3l at fitlinxx.com> wrote

> So I wonder if some of the confusion is people familiar with other
> language's augmented assignment trying to extrapolate that into Python
> and then running into the pre-existing differences in assignment
> versus binding?

Yes.  Understanding the difference is one of the major keys to
understanding Python.  So here is another attempt from me, based on some of
the issues raised by the Augmented Assignement thread, to explain the
difference.  (Call this What I Wish Someone Had Written Years Ago - before
I spend a couple weeks, and years since, trying to get what is going on.)
---

Most computer languages are based on and built around a model of a computer
as having a sequence of memory locations (linear store) labelled and
accessed by integers.  As a (major) convenience, particular locations or
sequential blocks thereof can be named.  Within a particular naming
context, the block represented by a name is fixed.  Morever, the name is
generally unique
(absent special devices like union statements and not counting indirect
access via pointers as a 'name').  So a name assignment expression or
statement (name EQ expression, where EQ may be '=' or something else,
depending on the particular language) says to put a particular value into
the particular memory block represented by the name.  To do so requires
size and possibly type compatibility.  Examples using C:

int a, b;        // &a = 4832, for instance, &b = 4836 (or 4828); a==0 or
random
a = 1; b = 2 // &a and &b still same as before; a==1, b==2
a = b;          // &a and &b unchanged and unequal even though values now
same
a = 'haha'   // illegal in C







More information about the Python-list mailing list