Piet van Oostrum a écrit : >>>>>>SuperHik <[EMAIL PROTECTED]> (S) escribió: > > >>S> [EMAIL PROTECTED] wrote: >> >>>>python wrote: >>>> >>>>>after del list , when I use it again, prompt 'not defined'.how could i >>>>>delete its element,but not itself? >>>> >>>>This is a way: >>>> >>>>>>>a = range(10) >>>>>>>del a[:] >> >>S> or simply >>S> a = [] >> >>>>>>>a >>>> >>>>[] > > > Then you *have* deleted the list
Not necessarily: >>> a = range(10) >>> b = a >>> id(a) 1078034316 >>> id(b) 1078034316 >>> a is b True >>> a = [] >>> b [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> id(a) 1078043724 >>> id(b) 1078034316 >>> What as been deleted is the association ('binding') between the name 'a' and the list object at 1078034316. This object won't be suppressed until there are no more names bound to it. > and created a new one, which is different > from keeping the list and deleting the elements: indeed !-) -- http://mail.python.org/mailman/listinfo/python-list