The meaning of "=" (Was: tough-to-explain Python)

Paul Boddie paul at
Wed Jul 8 16:53:44 CEST 2009

On 8 Jul, 16:04, kj <no.em... at> wrote:
>   <identifier> = <expression>
> and not to those like, for example,
>   <identifier>[<expression>] = <expression>
> or
>   <identifier>.<identifier> = <expression>
> The former are syntatic sugar for certain namespace modifications
> that leave objects unchanged.  The latter are syntactic sugar for
> certain object-modifying method calls that leave namespaces unchanged.

Almost. The latter can modify namespaces - the objects themselves -
but through properties or dynamic attribute access, they may choose
not to modify such a namespace. Really, we can phrase assignment (=)
as follows:

<thing> = <expression> # make <thing> refer to the result of

Here, <thing> has to provide something that can be made to refer to
something else, such as a name within a namespace - the first and last
of your cases - or an item or slice within a sequence - the special
second case which is actually handled differently from the other

Meanwhile, the <expression> will always provide an object to refer to,
never anything of the nature of <thing> referring to something else.
In other words, if you have this...

x[1] = y[2]

...then the <expression> which is y[2] will yield an object which is
then assigned to x[1]. The concept of y[2] is not assignable - it must
be fully evaluated and produce the object at location #2 in the
sequence for assignment.

I suppose you could say that the left-hand side <thing> is like a sign
on a signpost which always points to a real place, not another sign on
a signpost. You could stretch this analogy by treating sequences as
signposts holding many signs, each adjustable to point to something
different. Since signposts (not the individual signs) are located in
real places, they would naturally be acceptable as targets of
assignments: where the signs are allowed to point to. Indeed, this
would be a world of signposts with the occasional primitive value
mixed in to keep weary travellers interested. ;-)


More information about the Python-list mailing list