Python TypeError: 'int' object is not subscriptable — Causes & Fix
What Does This Error Mean?
Python raises TypeError: 'int' object is not subscriptable when you use the bracket notation [] on an integer. Only sequences (lists, tuples, strings) and mappings (dicts) support subscript access. An integer value has no index.
Common Causes (With Code)
1. Confusing a variable holding an int with a list
❌ Causes the error
count = 42
print(count[0])
# TypeError: 'int' object is not subscriptable
2. A function returns an int but you treat it as a list
❌ Causes the error
def get_score():
return 95 # returns int, not a list
score = get_score()
print(score[0]) # TypeError: 'int' object is not subscriptable
3. Off-by-one indexing assignment — int on left side of brackets
❌ Causes the error
data = [10, 20, 30]
length = len(data) # length = 3 (int)
print(length[0]) # TypeError: 'int' object is not subscriptable
4. Overwriting a list variable with an integer mid-code
❌ Causes the error
items = [1, 2, 3]
items = len(items) # items is now 3 (int)
print(items[0]) # TypeError: 'int' object is not subscriptable
How to Fix It
Fix 1 — Make sure you're indexing the right variable (list, not int)
✅ Correct
data = [10, 20, 30]
print(data[0]) # 10 — index the list, not its length
Fix 2 — Update the function to return a list when needed
✅ Correct
def get_scores():
return [95, 87, 72] # returns list
scores = get_scores()
print(scores[0]) # 95
Fix 3 — Use a separate variable for len(), never overwrite the list
✅ Correct
items = [1, 2, 3]
item_count = len(items) # keep `items` as the list
print(items[0]) # 1 ✅
print(item_count) # 3 ✅
Fix 4 — Use type() to debug which type a variable actually has
✅ Diagnostic tip
x = some_function()
print(type(x)) # Check before indexing
# → you cannot use [], return a list instead
Frequently Asked Questions
Does this only happen with integers?
No — the pattern applies to any non-subscriptable type. You can also see 'NoneType' object is not subscriptable, 'bool' object is not subscriptable, etc. The fix is always the same: make sure the variable holds a sequence (list, tuple, str) before using [].
How do I get individual digits from an integer?
Convert it to a string first, then index:
n = 2026
digits = str(n)
print(digits[0]) # '2'
print(int(digits[0])) # 2 (back to int)