Why is this?

Paolino paolo_veronelli at tiscali.it
Wed Aug 10 08:17:34 EDT 2005


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
> 

> And, just to add to my confusion:
> 
> 
>>>>[[]]*2
> 
> [[], []]
> 
>>>>[[], []] == [[]]*2
> 
> True
This confuses me also,looks like empty lists share same object.

Paolino


	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it



More information about the Python-list mailing list