why no 'length' method in sequences ?
Terry Reedy
tejarex at yahoo.com
Thu Apr 18 12:33:23 EDT 2002
"Richard Gruet" <rjgruet at yahoo.com> wrote in message
news:a9mqn3$5ao$1 at aphrodite.grec.isp.9tel.net...
> Hi all
>
> I wonder why there is no 'length' (or 'len') method - or attribute -
in the
> sequences types. Having to use the built-in function len() doesn't
sound
> very Object-Oriented to me. I understand that the built-in function
len()
> must be kept for compatibility reasons, but why not to add also the
method
> len() to the sequence types ? Is there a reason ?
Python is object-based and increasingly object-oriented but not
Object-Oriented. Originally, Guido decided that functions/methods
common to many types should be functions rather than methods. Besides
which, only some types had/have methods. Tuples still do not have
methods (that I know of). Strings did not until fairly recently.
With respect to class instances, len(instance) is easily redirected to
__len__, which is consonat with Python's current policy for naming
common, cross-class methods.
Terry J. Reedy
More information about the Python-list
mailing list