John Salerno wrote: > Steven Bethard wrote: > > > > lst[:] = [] > > lst = [] > > What's the difference here?
L[:]= modifies the object in place, L=[] binds the variable to a new object. compare and contrast: >>> L = ["a", "b", "c"] >>> M = L >>> L ['a', 'b', 'c'] >>> M ['a', 'b', 'c'] >>> L is M True >>> L[:] = [] >>> L [] >>> M [] >>> L is M True >>> L = ["a", "b", "c"] >>> M = L >>> L ['a', 'b', 'c'] >>> M ['a', 'b', 'c'] >>> L = [] >>> L [] >>> M ['a', 'b', 'c'] >>> L is M False </F> -- http://mail.python.org/mailman/listinfo/python-list