General

TypeError: unsupported operand type(s) for +: 'int' and 'str' — What It Means and How to Fix It

2026-12-04 · 5 min · Lint Team

Few Python errors are as common — or as initially confusing — as this one:

Traceback (most recent call last):
File "app.py", line 12, in <module>
total = count + value
~~~~~~^~~~~~~
TypeError: unsupported operand type(s) for +: 'int' and 'str'


What it means: you used + between an integer and a string, and Python refuses to guess which one you meant. Unlike JavaScript, Python never converts between numbers and text implicitly. The message names the two types in order: the left operand is an int, the right one is a str. (If the string is on the left, you get the sibling message instead: TypeError: can only concatenate str (not "int") to str — same problem, mirrored.)

Got a different error in front of you? Paste it in and get a plain-English explanation plus the usual fix — 72 known patterns, no account.

Decode my error →Free, no signup for your first checks.


Why it happens



One of the two values is a string that you expected to be a number. The usual sources:

  • input() always returns a string. age = input("Age: ") gives you "30", not 30 — so age + 1 fails.
  • Data from files and forms is text. CSV cells, form fields, query parameters, and environment variables all arrive as strings, even when they look numeric.
  • JSON values you assumed were numbers. An API that returns "price": "19.99" (quoted) instead of 19.99 will trigger this the first time you do arithmetic.
  • You actually wanted text. Sometimes the intent was concatenation — building a message — and the number simply was not converted.


Fix 1: convert explicitly (when you want arithmetic)



Convert the string to a number before adding. Use int() for whole numbers, float() for decimals:

count = int(input("How many? "))
total = count + 1


If the value might not be numeric, guard the conversion instead of crashing:

try:
count = int(value)
except ValueError:
raise ValueError(f"expected a number, got {value!r}")


Raising with the offending value in the message turns the next debugging session into a ten-second one.

Fix 2: format instead of add (when you want text)



If the goal was a string — a message, a label, a filename — do not add at all. Format:

message = f"You have {count} items"
# or, older style:
message = "You have " + str(count) + " items"


The f-string version is clearer and avoids the error entirely, because formatting converts for display without pretending to do arithmetic.

Fix 3: find the culprit (when you do not know which side is the string)



Print the types at the failing line:

print(type(count), repr(count))
print(type(value), repr(value))


repr() matters: it shows quotes around strings, so '5' and 5 stop looking identical in your terminal. Nine times out of ten, one of them is '5' — a string wearing a number's clothes — and its source is one of the four cases above. Fix it at the source (convert where the value enters your program) rather than sprinkling int() at every use site; boundary conversion keeps the rest of your code honest.

The one-sentence version



TypeError: unsupported operand type(s) for +: 'int' and 'str' means "one of these is text, and Python will not guess." Decide whether you wanted math or text, convert at the boundary, and the error is gone for good.

This is one of the five patterns in our hub guide, What Does This Error Actually Mean?, which also covers KeyError, ModuleNotFoundError, "is not a function", and CORS. For the error in front of you right now, paste it into the free error decoder and get the plain-English version plus the usual fix.
📌 Prices and tool count in this article may be outdated. Lint now ships 16 tools with Pro at $12/mo, or $39/year founding. See the current pricing page.
Try Lint free — no signup, code-aware
Free · no account needed · open full toolkit →
L
Lint Team
Lint Tools — AI writing for developers

Stop letting Grammarly break your code

18 AI and browser tools built for developers. Code-aware parsing.

Try free — no signup View pricing
Or upgrade to Pro for 500 checks a day · All tools · No ads

Need more than free tools?

Unlock 500 checks a day, larger text capacity, and priority support.

View pricing → Upgrade Lint — Pro $12/mo or $39/yr founding
💬