I’m working on a Python script that should calculate the sum of a list of numbers. However, I’m encountering a TypeError
when I run the code. Here is a minimal example:
numbers = [1, 2, 3, '4']
total = sum(numbers)
print(total)
The error message is: TypeError: unsupported operand type(s) for +: 'int' and 'str'.
Could someone explain why this error is occurring and how I can fix it?
New contributor
Shah Zaib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2