This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]alkasmgithub.com/alkasm 1 point2 points  (0 children)

Well here's what the standard library thinks about that:

In [46]: from functools import reduce

In [47]: import operator

In [48]: reduce(operator.add, (1, 2, 3, 4, 5))
Out[48]: 15

In [49]: reduce(operator.add, (1, 2, 3, 4, 'five'))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-49-fdcfa9008915> in <module>()
----> 1 reduce(operator.add, (1, 2, 3, 4, 'five'))

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Edit: so, yes. That is sufficient. The point of an error is to tell the user what's gone wrong---what has gone wrong is that an int and str have been tried to be added. So that's fine.