strange behaviour of sum()

Inyeol Lee inyeol.lee at
Thu Nov 20 02:17:49 CET 2003

On Wed, Nov 19, 2003 at 11:46:07PM +0100, Jan-Erik Meyer-Lütgens wrote:
> I'd ran into trouble when I've used sum() naively:
> The other strange behaviour is:
>     sum(['my', 'pet', 'fish', 'eric'], '')
> results in:
>     TypeError: sum() can't sum strings [use ''.join(seq) instead]
> If there is a special treatment for strings, why doesn't sum()
> use ''.join(seq) itself, instead of telling me that I should
> use it? But in fact sum() should call operator.add(), even
> for strings:

There was a duscussion on this in python-dev. See thread starting from

and Guido's summary at


-Inyeol Lee

More information about the Python-list mailing list