TypePython Error

TypeError

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Traceback

terminal
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    message = "Age: " + age
TypeError: unsupported operand type(s) for +: 'int' and 'str'

What causes this error

A binary operator was applied to two objects of incompatible types. Python does not perform implicit type coercion between strings and numbers or other mismatched types.

How to fix it

Convert types explicitly: use str() for string concatenation, int()/float() for arithmetic. Use f-strings for string formatting. Check variable types when the error is unexpected.

Code that causes this error

Broken
age = 25
message = "Age: " + age

Fixed code

Fixed
age = 25
message = f"Age: {age}"
# or: message = "Age: " + str(age)

About TypeError

This error occurs when you use a binary operator (+, -, *, /, etc.) with operands of incompatible types. Python does not implicitly convert types in arithmetic — unlike JavaScript where `'5' + 3` silently produces `'53'`, Python explicitly raises a TypeError. The most common case is trying to concatenate a string and a number with the `+` operator.

Other triggers include adding a list and a tuple, subtracting strings, or using comparison operators between incompatible types (in Python 3, `'a' < 5` raises TypeError). The error message clearly states which operator was used and which types were involved, making diagnosis straightforward. The fix is to explicitly convert types: use `str()` when building strings, `int()` or `float()` when doing arithmetic, or use f-strings which handle type conversion automatically.

Common scenarios

1

Performing operations between incompatible types like strings and integers

2

Calling methods that return None and chaining operations on the result

3

Passing the wrong number or type of arguments to a function

4

Using bracket notation on objects that do not support indexing

Related errors