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

Aahz aahz at pythoncraft.com
Wed Oct 9 05:54:54 CEST 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