Message376536
As Marco says, the exception message is because the default value for start is 0, and you can't concatenate strings to the integer 0.
You get the same error if you try to concatenate lists:
py> sum([[], []])
TypeError: unsupported operand type(s) for +: 'int' and 'list'
However, even if you provide a default of the empty string, "", sum will still reject string arguments. This is intentional, as repeatedly concatenating strings may be extremely inefficient and slow, depending on the specific circumstances.
The default of 0 is documented, as is the intention that sum be used only for numeric addition. See `help(sum)` or the docs on the website. |
|
Date |
User |
Action |
Args |
2020-09-07 22:16:23 | steven.daprano | set | recipients:
+ steven.daprano, Phillip.M.Feldman@gmail.com, mpaolini |
2020-09-07 22:16:23 | steven.daprano | set | messageid: <1599516983.75.0.295746236329.issue41740@roundup.psfhosted.org> |
2020-09-07 22:16:23 | steven.daprano | link | issue41740 messages |
2020-09-07 22:16:23 | steven.daprano | create | |
|