On Apr 3, 11:48 pm, Tim Wintle <tim.win...@teamrubber.com> wrote:
> del mylist[:]
> * or *
> mylist[:] = []
> * or *
> mylist = []
>
> which, although semantically similar are different as far as the
> interpreter are concerned (since two of them create a new list):
>

Only the last item creates a new list of any consequence.  The first
two retain the original list and delete or discard the items in it.  A
temporary list gets created in the 2nd option, and is then used to
assign new contents to mylist's [:] slice - so yes, technically, a new
list *is* created in the case of this option. But mylist does not get
bound to it as in the 3rd case.  In case 2, mylist's binding is
unchanged, and the temporary list gets GC'ed almost immediately.

-- Paul
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to