Error guide · TypeError
TypeError: unsupported operand type(s) for +: 'int' and 'str'
You used an operator with two kinds of value that Python cannot combine.
Example
total = 5 print(total + "3")
What Python says
TypeError: unsupported operand type(s) for +: 'int' and 'str'
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
+ can add two numbers or join two pieces of text, but it will not guess how to combine a number with text. The types in the message tell you which side is which: here an int on the left and a str on the right. Convert one side so that both match.
How to fix it
total = 5 print(total + int("3"))
Output: 8
Tips
- Convert text to a number with
int()orfloat()to do maths. - Convert a number to text with
str(), or use an f-string, to build a message. - The same message appears for
-and/. With*, text times a whole number repeats the text instead.