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

Erik Max Francis max at alcyone.com
Wed Oct 9 04:09:21 CEST 2002


Greg Brunet wrote:

> I'm just trying to learn Python, and one thing that struck me as odd
> was that to delete a specific list element, I need to use a statement
> instead of a method like I use for almost everything else I do on the
> list.  This seems a bit inconsistent.  Why wouldn't it be a method?

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

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Winners are men who have dedicated their whole lives to winning.
\__/ Woody Hayes
    The laws list / http://www.alcyone.com/max/physics/laws/
 Laws, rules, principles, effects, paradoxes, etc. in physics.



More information about the Python-list mailing list