Write Python. Understand every error.

Open the editor

Error guide · TypeError

TypeError: can only concatenate str (not "int") to str

An operation was used with a type of value it does not work with, such as adding text and a number.

Example

age = 19
print("I am " + age + " years old")

What Python says

TypeError: can only concatenate str (not "int") to str

As printed by Python 3.12. Other versions may word it slightly differently.

Try this code in Py-CRAFT

Why it happens

Python never guesses whether you meant text or a number. + joins two strings or adds two numbers, but it refuses to mix them. The same error appears when you call a function with the wrong number of arguments, or call something that is not a function.

How to fix it

age = 19
print("I am " + str(age) + " years old")

Output: I am 19 years old

Tips

Learn the ideas behind it

Other common errors

Share this page: