On Tue, Nov 25, 2008 at 9:23 AM, Arnaud Delobelle <[EMAIL PROTECTED]>wrote:
> Jason Scheirer <[EMAIL PROTECTED]> writes: > > > On Nov 24, 10:34 pm, [EMAIL PROTECTED] wrote: > >> Hi Python experts! Please explain this behavior: > >> > >> >>> nn=3*[[]] > >> >>> nn > >> [[], [], []] > >> >>> mm=[[],[],[]] > >> >>> mm > >> > >> [[], [], []] > >> > >> Up till now, 'mm' and 'nn' look the same, right? Nope! > >> > >> >>> mm[1].append(17) > >> >>> mm > >> [[], [17], []] > >> >>> nn[1].append(17) > >> >>> nn > >> > >> [[17], [17], [17]] > >> > >> ??? > >> > >> Python 2.5 Win XP > >> > >> Thanks! > > > > You're creating three references to the same list with the > > multiplication operator. > > There's no need to introduce references: you're creating a list with the > same object at each position. > > [...] > > Python is pass-by-reference, not pass-by-value. > > It's certainly not pass-by-reference, nor is it pass-by-value IMHO. Please don't get into this here. We have enough threads for this already. > > > -- > Arnaud > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list