<br><br><div class="gmail_quote">On Tue, Nov 25, 2008 at 9:23 AM, Arnaud Delobelle <span dir="ltr"><<a href="mailto:arnodel@googlemail.com">arnodel@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Jason Scheirer <<a href="mailto:jason.scheirer@gmail.com">jason.scheirer@gmail.com</a>> writes:<br>
<br>
> On Nov 24, 10:34 pm, <a href="mailto:alexander.gen...@gmail.com">alexander.gen...@gmail.com</a> wrote:<br>
>> Hi Python experts! Please explain this behavior:<br>
>><br>
>> >>> nn=3*[[]]<br>
>> >>> nn<br>
>> [[], [], []]<br>
>> >>> mm=[[],[],[]]<br>
>> >>> mm<br>
>><br>
>> [[], [], []]<br>
>><br>
>> Up till now, 'mm' and 'nn' look the same, right? Nope!<br>
>><br>
>> >>> mm[1].append(17)<br>
>> >>> mm<br>
>> [[], [17], []]<br>
>> >>> nn[1].append(17)<br>
>> >>> nn<br>
>><br>
>> [[17], [17], [17]]<br>
>><br>
>> ???<br>
>><br>
>> Python 2.5 Win XP<br>
>><br>
>> Thanks!<br>
><br>
> You're creating three references to the same list with the<br>
> multiplication operator.<br>
<br>
There's no need to introduce references: you're creating a list with the<br>
same object at each position.<br>
<br>
[...]<br>
> Python is pass-by-reference, not pass-by-value.<br>
<br>
It's certainly not pass-by-reference, nor is it pass-by-value IMHO.</blockquote><div><br>Please don't get into this here. We have enough threads for this already.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
--<br>
Arnaud<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>