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

Denis Heidtmann denis.heidtmann at gmail.com
Wed Jan 29 02:34:13 CET 2014


On Tue, Jan 28, 2014 at 5:19 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> 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


Glad to hear it.  That is what I was hoping, but I did not want to question
a helpful person.

-Denis H.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140128/ef712413/attachment.html>


More information about the Tutor mailing list