[Tutor] When is = a copy and when is it an alias

Denis Heidtmann denis.heidtmann at gmail.com
Mon Jan 27 18:04:17 CET 2014


Thanks for the responses.

The distinction between replacement and modification seems to capture the
essential aspect and helps to clarify the issue for me.

spir:
Quite the opposite, in python "symbolic assignment" (where the right side
also is a symbol) never copies, in fact never creates a new value, but bind
the left symbol to the same, unique value, as the right symbol.

If this is accurate, I can see crazy bugs in my future until I internalize
it.

Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[2,3]
>>> b=[10,20]
>>> a[0]=b[0]
>>> a
[10, 3]
>>> b[0]=100
>>> a
[10, 3]

Apparently a[0]=b[0] does not qualify as "symbolic assignment" in this
case. a[0] is not a reference to b[0].  I think I see the essential
distinction.  Experience will complete the picture for me.

-DH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140127/82155a58/attachment.html>


More information about the Tutor mailing list