The short answer: 1) backwards compatibility and 2) there's not enough of a difference for it to really matter. For a more detailed explanation, read on.
The idiomatic Python approach to such operations is special methods which aren't intended to be called directly. For example, to make x + y
work for your own class, you write a __add__
method. To make sure that int(spam)
properly converts your custom class, write a __int__
method. To make sure that len(foo)
does something sensible, write a __len__
method.
This is how things have always been with Python, and I think it makes a lot of sense for some things. In particular, this seems like a sensible way to implement operator overloading. As for the rest, different languages disagree; in Ruby you'd convert something to an integer by calling spam.to_i
directly instead of saying int(spam)
.
You're right that Python is an extremely object-oriented language and that having to call an external function on an object to get its length seems odd. On the other hand, len(silly_walks)
isn't any more onerous than silly_walks.len()
, and Guido has said that he actually prefers it (http://mail.python.org/pipermail/python-3000/2006-November/004643.html).