Write Python. Understand every error.

Open the editor

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.

Try this code in Py-CRAFT

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

Learn the ideas behind it

Other common errors

Share this page: