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

Alan Gauld alan.gauld at btinternet.com
Wed Jan 29 02:19:54 CET 2014


On 28/01/14 19:00, Denis Heidtmann wrote:
> On Tue, Jan 28, 2014 at 12:28 AM, spir <denis.spir at gmail.com

This is getting confusing with two times Denis!

> <mailto:denis.spir at gmail.com>> wrote:
>
>                 a = [1,[2,3]]

I think the above line is a mistake. If Denis(spir) had missed
this out his code would work as he describes, but with it he
reassigns 'a' to a new list and, as you say breaks the connection.

If you forget about that line and keep a pointing at the original 
[1,[1,2]] list then the following code makes sense.

>                 a[0] = 0
>                 b
>
>     [0, [1, 2]]                  # this is where I get lost.
>
>                 a[1] = [0,0]
>                 b
>
>     [0, [0, 0]]


> My python gets a different result:

So does mine, and I suspect so does denis' (spir).
I think he made a mistake with the second assignment to a.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list