On Wed, Feb 16, 2011 at 09:50, Brett Ritter <swift...@swiftone.org> wrote: > On Wed, Feb 16, 2011 at 12:39 PM, Richard D. Moores <rdmoo...@gmail.com> > wrote: >> from <http://docs.python.org/py3k/tutorial/introduction.html#lists> : >> >>>>> # Clear the list: replace all items with an empty list >>>>> a[:] = [] >>>>> a >> [] >> >> I've been using >>>>> a = [] >>>>> a >> [] >> >> What's the difference? > > a = [] > > This sets the variable "a" to refer to a new list > > a[:] = [] > > This replaces the existing content of a with empty contents. > > Check out this example in interactive mode > >>>> a = [1,2,3] >>>> b = a >>>> a = [] >>>> print a > [] >>>> print b > [1, 2, 3] > > > Versus: > >>>> a = [1,2,3] >>>> b = a >>>> a[:] = [] >>>> print a > [] >>>> print b > []
Ah, got it! Thanks very much. Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor