properly delete item during "for item in..."

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Jul 17 12:44:55 EDT 2008


On Thu, 17 Jul 2008 09:27:27 -0700, Ratko wrote:

> for item in myList:
>    del item
> 
> Would this actually delete the item from the list or just decrement
> the reference counter because the item in myList is not associated
> with name "item" anymore (but still is with myList[itemIndex])? In
> other words, is "item" a temporary reference to myList[itemIndex] or
> is it actually that reference that myList has stored?

The latter.  Names are always bound to objects, you can't bind a name to
another name or reference in Python.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list