after del list , when I use it again, prompt 'not defined'.how could i delete its element,but not itself?
bdesth.quelquechose at free.quelquepart.fr
Sat Jun 3 02:26:03 CEST 2006
python a écrit :
> after del list , when I use it again, prompt 'not defined'.how could i
> delete its element,but not itself?
FWIW, del don't delete an object (not directly at least), it just delete
the name<->object association. If (and only if) it was the only name
referencing that object, then the object will be disposed too.
>>> list1 = [1, 2]
>>> list2 = list1
>>> del list2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'list2' is not defined
More information about the Python-list