strange behavor....

Terry Reedy tjreedy at udel.edu
Sat Nov 13 14:19:19 EST 2010


On 11/13/2010 11:29 AM, Mark Wooding wrote:

> Alas, Python is actually slightly confusing here, since the same
> notation `=' sometimes means assignment and sometimes means mutation.

I disagree somewhat. An object is mutated by an internal assignment.
"ll[0] = 1" assigns 1 to the 0 slot of ll.
"o.a = 1" assigns 1 to the 'a' attribute of o.
This which might be implemented by assigning 1 to the 'a' slot of 
o.__dict__, just as "a=1" might be implemented by assigning 1 to the 'a' 
slot of a namespace dict.

Assignment *always* binds an object to a target. Names are just one 
possible target. And, of course, assignment always mutates something -- 
a set of associations -- even if the 'something' is not a Python object 
itself.

So '=' always means assignment/binding by mutation. The question is what 
gets bound to what in what set of associations. The rest of your post 
helps clarify that.

-- 
Terry Jan Reedy




More information about the Python-list mailing list