The error TypeError: unsupported operand type(s) for +: 'int' and 'str' happens when you use + between an integer and a string. In Python, + means numeric addition for numbers and concatenation for strings; it does not automatically convert one type to the other. You must convert the number to a string (or the string to a number, depending on what you want). This guide shows how.

What this error means

+ is defined for “number + number” and “string + string”, but not for “number + string” or “string + number”. So 10 + " apples" or "I am " + 25 + " years old" raises this TypeError. Python does not guess whether you want addition or concatenation, so you must make the types match explicitly.

Common causes

  • Building a message with a number. You concatenate strings and forget that the number must be converted to a string first.
  • input() returns a string. Even if the user types digits, input() returns a string. Using that string in numeric addition, or mixing it with strings using +, can cause type errors. For invalid numeric input see ValueError: invalid literal for int().
  • Data from files or APIs. Numbers often arrive as strings; they need conversion before arithmetic or before being embedded in strings.

Example that causes the error

age = 25
message = "I am " + age + " years old"  # TypeError: can't add str + int

Fix 1: convert the number with str()

age = 25
message = "I am " + str(age) + " years old"
print(message)  # I am 25 years old

Fix 2: use f-strings (recommended)

F-strings convert values to strings automatically and are easier to read.

age = 25
message = f"I am {age} years old"
print(message)

Fix 3: handle user input correctly

input() always returns a string. Convert to int or float for math; use str() or f-strings when building output.

age_input = input("Enter your age: ")  # string
age = int(age_input)                   # int for calculations
next_year = age + 1
print(f"Next year you'll be {next_year}")

Next steps: Errors & Exceptions · ValueError: invalid literal for int() · Data types