sum and strings
Fredrik Lundh
fredrik at pythonware.com
Fri Aug 18 15:46:50 EDT 2006
Paddy wrote:
> Here is where I see the break in the 'flow':
>
>>>> 1+2+3
> 6
>>>> sum([1,2,3], 0)
> 6
>>>> [1] + [2] +[3]
> [1, 2, 3]
>>>> sum([[1],[2],[3]], [])
> [1, 2, 3]
>>>> '1' + '2' + '3'
> '123'
>>>> sum(['1','2','3'], '')
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> TypeError: sum() can't sum strings [use ''.join(seq) instead]
do you often write programs that "sums" various kinds of data types, and
for which performance issues are irrelevant?
or are you just stuck in a "I have this idea" loop?
</F>
More information about the Python-list
mailing list