TypeError in Python — What It Means and How to Fix It
What Python's TypeError exception means and how to resolve it.
Published October 27, 2026
TypeError is raised when an operation or function is applied to an object of the wrong type, such as adding an int to a string.
What it means and why it happens
Typical causes: mixing types in operators, calling a non-callable, passing the wrong number or type of arguments or iterating over None.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Practical examples
Code that triggers it
total = 5 + '3'The fix
total = 5 + int('3')
label = f'Total: {total}'Check types while debugging
print(type(x), repr(x))
assert isinstance(x, (int, float))Common mistakes
- Assuming input() returns numbers.
- Calling None or a variable shadowing a function.
- Forgetting parentheses or self.
Key takeaways
- TypeError: TypeError is raised when an operation or function is applied to an object of the wrong type, such as adding an int to a string.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
'NoneType' object is not subscriptable?
A function returned None; check the return value before indexing.
How do I find which line caused TypeError?
The error message and stack trace show the file and line; start there and work backwards.