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

Tim Roberts timr at probo.com
Thu Oct 10 08:22:24 CEST 2002

Padraig Brady <Padraig at Linux.ie> wrote:
>Being a python newbie myself this strck me as a little inconsistent.
>why can't you do:

The way I see it, THOSE are inconsistent.  Think about it in an
object-oriented way.  It doesn't make sense to ask an object to "delete"
itself, because the object isn't in control of where it is stored.  You
have to ask the OWNER of the object to do the delete.  It's the OWNER that
has to take an action.  Thus, something like "l.del([1])" would be a bit
more consistent.

This is the same as C++; objects are deleted using the "delete" operator,
not by asking an object to delete itself.

>Same goes for len() et. al.

Well, the len() function does call a a method.  Now, it's just syntactic
sugar.   However, until Python 2.0, types like strings could not have
methods, so you needed a global function.
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.

More information about the Python-list mailing list