On 2016-03-24, Steven D'Aprano <st...@pearwood.info> wrote: > On Fri, 25 Mar 2016 02:03 am, Jon Ribbens wrote: >> On 2016-03-24, BartC <b...@freeuk.com> wrote: >>> On 24/03/2016 14:08, Jon Ribbens wrote: >>>> if you thought you needed to do that then most likely what you >>>> should actually be doing is re-writing your code so you no longer >>>> need to. However, you could do: >>>> >>>> L[:] = [0] * len(L) >>> >>> OK, but that's just building a new list as I've already mentioned. >> >> No it isn't, it's replacing the elements in-place, that's what the >> "L[:]" bit means. Replacing the list object itself would be: >> L = [0] * len(L) > > Yes it is: a new list is built, copied, then discarded.
Obviously (as already mentioned in my earlier reply). But the point is that it is not "just building a new list", as if that were true then L would not be pointing to the same list afterwards. -- https://mail.python.org/mailman/listinfo/python-list