sum and strings

Georg Brandl g.brandl-nospam at gmx.net
Fri Aug 18 15:06:51 EDT 2006


Paddy wrote:
> Sybren Stuvel wrote:
>> Paddy enlightened us with:
>> > Well, after all the above, there is a question:
>> >
>> >   Why not make sum work for strings too?
>>
>> Because of "there should only be one way to do it, and that way should
>> be obvious". There are already the str.join and unicode.join methods,
>> which are more powerful than sum.
>>
>> Sybren
> I get where you are coming from, but in this case we have a function,
> sum, that is not as geeral as it could be. sum is already here, and
> works for some types but not for strings which seems an arbitrary
> limitation that impede duck typing.

Only that it isn't arbitrary.

> - Pad.
> 
> P.S. I can see why, and am used to the ''.join method. A newbie
> introduced to sum for integers might naturally try and concatenate
> strings using sum too.

Yes, and he's immediately told what to do instead.

Georg



More information about the Python-list mailing list