Musings about Python syntax

Fredrik Lundh fredrik at pythonware.com
Tue Oct 19 13:03:00 EDT 1999


steve_allison at my-deja.com wrote:
> i) if Python is as object orientated as is claimed, why are things like
> len() not member functions of list/tuples ?

hey, what makes you think len(obj) is less object-
oriented than obj.len() ?  it's just syntax, you know.

and except from a few builtin types, len actually
*is* a method, spelled __len__.  the len() function
is just there for your convenience...
    
also see:
http://www.python.org/doc/FAQ.html#6.5

> ii) similarly, why is 'del' operator like, and not a member function of
> those types that support it ?  having an 'append' method, but a 'del'
> operator seems peculiar.

"del" doesn't destroy an object, it removes
the name from the local namespace.

also see:
http://www.python.org/doc/FAQ.html#4.17
http://www.python.org/doc/FAQ.html#6.14

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list