Why is this?
Paolino
paolo_veronelli at tiscali.it
Wed Aug 10 08:30:07 EDT 2005
Paolino wrote:
> Jiri Barton wrote:
>
>>Hi everyone,
>>
>>I have a problem with initialization.
>>
>>
>>>>>a, b = [[]]*2
>>>>>a.append(1)
>>>>>b
>>
>>[1]
>>
>>Why is this? Why does not this behave like the below:
>>
>
> >>> a, b = [[]]*2
> >>> a==b
> True
Ooops I should write 'a is b'
>
>
>>And, just to add to my confusion:
>>
>>
>>
>>>>>[[]]*2
>>
>>[[], []]
>>
>>
>>>>>[[], []] == [[]]*2
>>
>>True
>
> This confuses me also,looks like empty lists share same object.
This is actually OK as lists are compared for their contents ;-)
> Paolino
>
>
>
>
>
>
> ___________________________________
> Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
> http://mail.yahoo.it
___________________________________
Aggiungi la toolbar di Yahoo! Search sul tuo Browser, e'gratis!
http://it.toolbar.yahoo.com
More information about the Python-list
mailing list