En Tue, 30 Sep 2008 01:03:07 -0300, namekuseijin <[EMAIL PROTECTED]>
escribió:
On 28 set, 15:29, process <[EMAIL PROTECTED]> 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
--
http://mail.python.org/mailman/listinfo/python-list