Message96013
"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
'xyzpdq'
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:42 | terry.reedy | set | recipients:
+ terry.reedy, georg.brandl |
2009-12-06 00:50:40 | terry.reedy | set | messageid: <1260060640.85.0.12368990118.issue7447@psf.upfronthosting.co.za> |
2009-12-06 00:50:38 | terry.reedy | link | issue7447 messages |
2009-12-06 00:50:37 | terry.reedy | create | |
|