Steven D'Aprano <[email protected]> added the comment:
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.
----------
nosy: +steven.daprano
title: string concatenation via `sum` -> Improve error message for string
concatenation via `sum`
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41740>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com