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.
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
- Convert numbers to text with
str()before joining them to strings. - Or use an f-string:
print(f"I am {age} years old"). - Convert text to numbers with
int()orfloat(), for example afterinput(). - "takes 1 positional argument but 2 were given" means the call has the wrong number of values.