Why is del(ete) a statement instead of a method?

Aahz aahz at pythoncraft.com
Tue Oct 8 23:54:54 EDT 2002


In article <3DA38FD1.DF32DCCC at alcyone.com>,
Erik Max Francis  <max at alcyone.com> wrote:
>
>It's because del is used for a lot more than just removing elements from
>lists.  It also removes keys from dictionaries, and can unbind
>variables:
>
>>>> x = 1
>>>> del x
>>>> x
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>NameError: name 'x' is not defined

You get a different error in a function:

def f():
    x = 1
    del x
    print x

f()
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/



More information about the Python-list mailing list