list.append problem?
Ignacio Vazquez-Abrams
ignacio at openservices.net
Mon Oct 1 17:55:46 EDT 2001
On 1 Oct 2001, newgene wrote:
> I am a newer of python. I have a problem like this code:
>
> >>> a=b=c=[]
> >>> a.append(1)
> >>> b.append(2)
> >>> c.append(3)
> >>> a
> [1, 2, 3]
> >>> b
> [1, 2, 3]
> >>> c
> [1, 2, 3]
>
> a,b,c become the same, although append method applied seperately.
> It's really strange and unreasonable.
This is because a, b, and c all contain a reference to the same list.
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list
mailing list