Wolfgang Maier added the comment:
>This implies sum() should accept str, unicode, list, tuple, bytearray, buffer,
>and xrange.
and in fact it *does* accept all these as input. It just refuses to add the
elements of the sequence if these elements are of certain types. Of course, the
elements of a string are strings themselves so this does not work:
>>> sum('abc', '')
Traceback (most recent call last):
File "<pyshell#88>", line 1, in <module>
sum('abc', '')
TypeError: sum() can't sum strings [use ''.join(seq) instead]
compare with a bytes sequence in Python3, where the elements are ints:
>>> sum(b'abc', 0)
294
but strings are also perfectly accepatble as input if you do not try to add
their str elements, but something else:
>>> class X (int):
def __add__(self, other):
return X(ord(other) + self)
>>> sum('abc', X(0))
294
=> the docs are right and there is no issue here.
----------
nosy: +wolma
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue23787>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com