TypeError in Python — unsupported operand type Fix (2026) | Tutorials Logic
What is This Error?
The TypeError occurs when an operation or function is applied to an object of inappropriate type. This is one of the most common Python errors and indicates a mismatch between expected and actual data types.
Error Messages:
TypeError: unsupported operand type(s) for +: 'int' and 'str'TypeError: 'int' object is not callableTypeError: can only concatenate str (not "int") to str
Common Causes
Quick Fix (TL;DR)
# ❌ Problem
result = "5" + 10 # TypeError!
# ✅ Solution: Convert types
result = int("5") + 10 # 15
result = "5" + str(10) # "510"
# ✅ Check types before operations
if isinstance(value, int):
result = value + 10
Common Scenarios & Solutions
Scenario 1: Mixing String and Number
Trying to perform arithmetic operations between strings and numbers.
age = "25"
next_year = age + 1 # TypeError!
price = 100
message = "Price: " + price # TypeError!
# Convert string to int for arithmetic
age = "25"
next_year = int(age) + 1 # 26
# Convert number to string for concatenation
price = 100
message = "Price: " + str(price) # "Price: 100"
# Or use f-strings (recommended)
message = f"Price: {price}" # "Price: 100"
# Or use format()
message = "Price: {}".format(price)
Scenario 2: Calling Non-Callable Object
Trying to call a variable or value as if it were a function.
number = 42
result = number() # TypeError: 'int' object is not callable
# Common mistake: shadowing built-in functions
list = [1, 2, 3]
new_list = list(range(5)) # TypeError!
# Don't add () if it's not a function
number = 42
result = number # Just use the value
# Don't shadow built-in names
my_list = [1, 2, 3] # Use different name
new_list = list(range(5)) # Now works
# If you accidentally shadowed, delete it
del list # Remove the variable
new_list = list(range(5)) # Now works
Scenario 3: Wrong Argument Types
Passing arguments of the wrong type to a function.
import math
result = math.sqrt("16") # TypeError: must be real number, not str
numbers = "1,2,3,4"
total = sum(numbers) # TypeError: unsupported operand type
import math
result = math.sqrt(16) # Pass number, not string
# Or convert first
result = math.sqrt(int("16"))
numbers = "1,2,3,4"
number_list = [int(x) for x in numbers.split(",")]
total = sum(number_list) # 10
Scenario 4: Iterating Over Non-Iterable
Trying to loop over an object that doesn't support iteration.
count = 5
for i in count: # TypeError: 'int' object is not iterable
print(i)
value = None
for item in value: # TypeError: 'NoneType' object is not iterable
print(item)
# Use range() for numbers
count = 5
for i in range(count): # 0, 1, 2, 3, 4
print(i)
# Check if value is iterable
value = None
if value is not None:
for item in value:
print(item)
# Or use default empty list
value = None
for item in value or []:
print(item)
Scenario 5: Indexing Non-Subscriptable Object
Trying to use indexing on objects that don't support it.
number = 12345
first_digit = number[0] # TypeError: 'int' object is not subscriptable
value = None
item = value[0] # TypeError: 'NoneType' object is not subscriptable
# Convert to string first
number = 12345
first_digit = str(number)[0] # "1"
# Check before indexing
value = None
if value is not None and len(value) > 0:
item = value[0]
Best Practices to Avoid This Error
Related Errors
Key Takeaways
- TypeError occurs when operations are performed on incompatible data types
- Cannot mix strings and numbers in arithmetic without explicit conversion
- Use int(), str(), float() to convert between types explicitly
- F-strings are the best way to format strings with variables
- Don't shadow built-in function names like list, dict, str, or sum
- Use isinstance() to check types before performing operations
Frequently Asked Questions
Level Up Your Python Skills
Master Python with these hand-picked resources
10,000+ learners
Free forever
Updated 2026
Related Python Topics