list.clear() missing?!?

John Salerno johnjsal at NOSPAMgmail.com
Tue Apr 11 16:59:28 EDT 2006


Fredrik Lundh wrote:
> 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:

Thanks guys, your explanations are really helpful. I think what had me 
confused at first was my understanding of what L[:] does on either side 
of the assignment operator. On the left, it just chooses those elements 
and edits them in place; on the right, it makes a copy of that list, 
right? (Which I guess is still more or less *doing* the same thing, just 
for different purposes)



More information about the Python-list mailing list