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

This error happens when Python tries to join a string and an integer with +.

In Python, + can join strings only when both values are strings. If one value is text and the other is a number, Python raises a TypeError.

Quick fix

name = "Age: "
age = 25
print(name + str(age))

# or
print(f"Age: {age}")

Convert the integer to a string before concatenation, or use an f-string for cleaner output.

What this error means

  • Python uses + to join strings only when both values are strings.
  • If one value is a string and the other is an integer, Python raises a TypeError.
  • The message means Python cannot automatically turn the int into text in this case.

For example, "Age: " + "25" works because both sides are strings.

But "Age: " + 25 fails because:

  • "Age: " is a str
  • 25 is an int

Why it happens

This error usually appears when:

  • You used + between text and a number.
  • A variable you expected to be text is actually an int.
  • Input was converted with int() earlier, then joined to a string later.
  • The error appears in print() statements, labels, and messages.

A common beginner mistake looks like this:

age = int(input("Enter your age: "))
print("Your age is: " + age)

age is no longer text after int(...). It is now an integer, so Python cannot concatenate it to a string with +.

Example that causes the error

Here is a short example:

print("Age: " + 25)

You will see an error like this:

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

Why?

  • Left side: "Age: "str
  • Right side: 25int

Python does not mix these types with +.

Fix 1: Convert the integer with str()

Use str() when you need text output.

age = 25
print("Age: " + str(age))

Output:

Age: 25

This is the most direct fix when you are building a string step by step.

Another example:

total = 50
message = "Total: " + str(total)
print(message)

Output:

Total: 50

If you want more detail, see how to convert int to string in Python.

Fix 2: Use f-strings

An f-string lets you place variables directly inside a string.

age = 25
print(f"Age: {age}")

Output:

Age: 25

This is often the cleanest option because Python handles the text conversion for display.

You can include multiple values too:

name = "Sam"
age = 25
print(f"{name} is {age} years old.")

Output:

Sam is 25 years old.

If you want to learn more, see how to format strings in Python.

Fix 3: Use print() with commas

For simple output, you do not need string concatenation at all.

age = 25
print("Age:", age)

Output:

Age: 25

This works because print() can display different data types together.

This is useful when you just want to show values on the screen and do not need to build one combined string first.

How to debug this error

When you see this error:

  1. Check the line mentioned in the traceback.
  2. Look for + used between values.
  3. Confirm the type of each variable.
  4. Check whether you used int() earlier.

Useful debugging commands:

type(age)
print(type(age))
print(age)
print("Age: " + str(age))

Example:

age = 25

print(type(age))
print(age)

Output:

<class 'int'>
25

If a value is int and you are trying to join it to a string with +, convert it only when creating output text.

When not to use str()

Do not convert numbers to strings if you still need to do math with them.

This is not a good idea:

price = str(10)
quantity = 2

# This will not do math correctly
# print(price * quantity)

Keep numbers as int or float for calculations:

price = 10
quantity = 2
total = price * quantity

print(f"Total: {total}")

Output:

Total: 20

A good rule is:

  • Use numbers for calculations
  • Convert to string only when creating text output

Common causes

Here are some common situations that trigger this error:

  • Using print("Total: " + total) when total is an int
  • Joining user-facing text with a number using +
  • Converting input to int() and later trying to concatenate it to text
  • Assuming Python will automatically convert int to str

This error is related to other + type problems too. If your code is adding two incompatible values, see TypeError: unsupported operand type(s) for +.

FAQ

Why does Python not automatically convert int to str here?

Python keeps numbers and text as different types to avoid unclear behavior and hidden bugs.

Should I use str() or an f-string?

Use str() for a direct fix. Use f-strings when you want cleaner output formatting.

Does this happen with float values too?

Yes. The same problem happens if you try to concatenate a string and a float with +.

Example:

print("Price: " + 9.99)

This also raises a TypeError.

Can print() avoid this error?

Yes. print("Value:", number) works because print() can display multiple value types together.

See also