sum works in sequences (Python 3)
Franck Ditter
franck at ditter.org
Wed Sep 19 10:41:20 EDT 2012
More information about the Python-list mailing list
Wed Sep 19 10:41:20 EDT 2012
- Previous message (by thread): A little morning puzzle
- Next message (by thread): sum works in sequences (Python 3)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello,
I wonder why sum does not work on the string sequence in Python 3 :
>>> sum((8,5,9,3))
25
>>> sum([5,8,3,9,2])
27
>>> sum('rtarze')
TypeError: unsupported operand type(s) for +: 'int' and 'str'
I naively thought that sum('abc') would expand to 'a'+'b'+'c'
And the error message is somewhat cryptic...
franck
- Previous message (by thread): A little morning puzzle
- Next message (by thread): sum works in sequences (Python 3)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list