count method only for lists?

Fredrik Lundh fredrik at pythonware.com
Fri Aug 27 09:29:08 CEST 1999


Stuart Reynolds <S.I.Reynolds at cs.bham.ac.uk> wrote:
> Does anyone know why there the count method is only defined for mutable
> sequences (i.e. lists) and not strings and tuples?

"Good question", to quote the FAQ.

in the old days, the answer used to be 'the design rule is that
immutable objects don't have methods', but that's no longer
true.  strings are likely to grow methods in 1.6, for example. 
and complex numbers already have them...

FAQ 6.4 gives the true background:

    http://www.python.org/doc/FAQ.html#6.4

    Long ago, it seemed unnecessary to implement any of
    these functions in C, so a standard library module "string"
    written in Python was created that performs string
    related operations.

> It seems as though the Python Library Reference (2.1.5.2
> Mutable Sequence Types) only describes lists and not
> mutable sequence types.

well, strings and tuples are not mutable, so that's
reasonable.

</F>





More information about the Python-list mailing list