What is not objects in Python?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Sep 30 10:05:55 CEST 2008

En Tue, 30 Sep 2008 01:03:07 -0300, namekuseijin <namekuseijin at gmail.com>  
> On 28 set, 15:29, process <circularf... at gmail.com> wrote:

>> Why isn't len implemented as a str.len and list.len method instead of
>> a len(list) function?
> Because postfix notation sucks.  The natural way of spelling is
> adjective+noun and verb+predicate.  That's one of the reasons I like
> Lisp better than Python.

Well, "natural" for English-speaking people... Noun+adjective is usually  
more "natural" In Spanish than the English word ordering.

Back to the original question, len(x) allows for a fast response without  
paying the overhead of a name lookup and then a method call.  
len(some_list) doesn't invoke some_list.__len__(), it just returns the  
value stored somewhere in the list object; same for other built-in  
objects. __len__ is searched as a last resort only.
The optimization could not be done if it were spelled x.len()

Gabriel Genellina

More information about the Python-list mailing list