I have the following code that sums the elements in a tuple:
t = ("j","h","w","j")
print(sum(t))
I got the following error:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Why does the error say int
when the tuple contains only strings?
From the docs: sum(iterable, /, start=0)
Sums start and the items of an iterable from left to right and returns the total.
You are trying to build the sum of start (which is an integer) and the elements of a tuple which contains strings.