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
 >>> id(list1)
1078043852
 >>> id(list2)
1078043852
 >>> del list2
 >>> list1
[1, 2]
 >>> list2
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
NameError: name 'list2' is not defined
 >>>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to