restriction on sum: intentional bug?

Christian Heimes lists at cheimes.de
Fri Oct 16 11:58:29 EDT 2009


Alan G Isaac schrieb:
> I expected this to be fixed in Python 3:
> 
>>>> sum(['ab','cd'],'')
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: sum() can't sum strings [use ''.join(seq) instead]
> 
> Of course it is not a good way to join strings,
> but it should work, should it not?  Naturally,

It's not a bug. sum() doesn't work on strings deliberately. ''.join()
*is* the right and good way to concatenate strings.

Christian



More information about the Python-list mailing list