Simple list.append() question
Quinn Dunkan
quinn at photo.ugcs.caltech.edu
Mon Apr 24 13:48:10 EDT 2000
On Mon, 24 Apr 2000 11:19:24 -0400, Matthew Hirsch <meh9 at cornell.edu> wrote:
>Hi All,
>
>I have this:
>>>> entire_list=[[]]*3
>>>> entire_list
>[[], [], []]
>>>> entire_list[0].append(1.23)
>>>> entire_list
>[[1.23], [1.23], [1.23]]
>
>I only want to append 1.23 to entire_list[0]. Why did it also append it
>to entire_list[1] and entire_list[2]?
When you multiply a list, you get multiple references to the *same* object.
See FAQ 4.50
More information about the Python-list
mailing list