functions vs methods

Ben Finney ben+python at
Sun Jul 22 05:08:13 EDT 2018

INADA Naoki <songofacandy at> writes:

> Please don't refer the FAQ entry.
> See this:

Interesting. Thanks for raising that bug report.

I offer my text as a starting point for a better explanation:

    Because ‘len’ works with *any* sequence, not only lists. To
    implement it as a method of each sequence type, it would have to be
    implemented on each type separately, which is a design that is
    needlessly more complex.

    This is common in Python: it uses so-called “duck typing”
    where the way an object behaves is more important than its type.
    Because “what is the length of this object” is a question valid for
    a broad variety of types, the design decision was made to allow it
    to accept any type for which that query makes sense.

Feel free to use that (or something derived from it) to improve the
documentation as you suggest.

 \       “Come on, if your religion is so vulnerable that a little bit |
  `\           of disrespect is going to bring it down, it's not worth |
_o__)               believing in, frankly.” —Terry Gilliam, 2005-01-18 |
Ben Finney

More information about the Python-list mailing list