This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients georg.brandl, terry.reedy
Date 2009-12-06.00:50:37
SpamBayes Score 2.1574303e-10
Marked as misclassified No
Message-id <>
"sum(iterable[, start]) 
Sums start and the items of an iterable from left to right and returns
the total. start defaults to 0. The iterable‘s items are normally
numbers, and are not allowed to be strings."

The last sentence is not currently true (3.1, assume also others).
It is the start value that cannot be a string.

>>> sum([1,2],'')
TypeError: sum() can't sum strings [use ''.join(seq) instead]

>>>sum(['xyz', 'pdq'], Zero()) # R Hettinger's universal zero class
works because start is not a string

>>> sum(['a','b'])
TypeError: unsupported operand type(s) for +: 'int' and 'str'
passes type(start) != str and only fails because + fails.

I am filing this as a doc issue as the easiest fix for the discrepancy
between doc and behavior. But the fix could be a behavior change, though
certain to be controversial. Given that, my  suggested revision is:
"The iterable‘s items are normally numbers. The start value is not
allowed to be a string."

I think this fits the followup sentence: "The fast, correct way to
concatenate a sequence of strings..."
Date User Action Args
2009-12-06 00:50:42terry.reedysetrecipients: + terry.reedy, georg.brandl
2009-12-06 00:50:40terry.reedysetmessageid: <>
2009-12-06 00:50:38terry.reedylinkissue7447 messages
2009-12-06 00:50:37terry.reedycreate