Why is this?

Jiri Barton jbar at hosting4u.cz
Wed Aug 10 06:40:54 EDT 2005


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 = [[], []]
>>> a.append(1)
>>> b
[]

And, just to add to my confusion:

>>> [[]]*2
[[], []]
>>> [[], []] == [[]]*2
True

Thanks in advance for the explanation.
jbar


BTW, if it matters...
Python 2.4.1 (#2, Mar 30 2005, 20:41:35)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2






More information about the Python-list mailing list