TypeError: 'int' object is not subscriptable — decoded
Exception: TypeErrorCategory: runtimeRaised at: the moment you index into a number
What this message means
subscriptable is the technical word for a container you can index with [ ] — lists, strings, tuples and dictionaries. An int is a single number, not a container, so x[0] on an integer has no meaning. Python says exactly that: the object you subscripted is an int, and an int cannot be subscripted.
The message almost never means your indexing syntax is wrong. It means the value you indexed is not the value you think it is — somewhere between creating the data and using it, the variable holds a plain number instead of the list, string or dict you expected.
Traceback (most recent call last):
File "main.py", line 3, in <module>
print(score[0])
~~~~~^^^
TypeError: 'int' object is not subscriptable
Read the underline: Python underlines the exact expression that was subscripted (score), not the [0]. Whatever name sits right before the bracket is the value that turned out to be an int.
A real example
def first_score(scores):
return scores[0]
result = first_score(85)
print(result[0])
Traceback (most recent call last):
File "main.py", line 6, in <module>
print(result[0])
~~~~~~^~
TypeError: 'int' object is not subscriptable
The bug is a mismatch between producer and consumer: first_score returns a single element (an int), but the caller keeps treating the return value as the whole list. This producer/consumer mismatch is the most common shape of this error — the fix is to decide which side is lying and correct it there.
The causes behind almost every case
- Indexing the result of a call that returns a number.
len(items)[0],int(text)[0],round(x)[1]— the call already produced anint, and you subscript it again. - A variable was overwritten with a number.
scores = total / len(scores)reuses the name, so a laterscores[0]now subscripts a float or int instead of the original list. - A loop variable shadows the list.
for score in scores:followed byprint(score[0])—scoreis one integer element;scoresis the list. - JSON or API data is a number, not a list.
data['count']is anint; only sequence fields likedata['items']can be indexed like a list. - Chaining subscripts one level too deep.
grid[0][0]is correct for a list of lists, but ifgridis a list of numbers, the second[0]subscripts anint.
The fix, step by step
- Look at the underlined name in the traceback — that is the variable holding the
int. - Print it just before the failing line:
print(type(name), repr(name)). Confirm it is really anintand see its value. - Trace backwards to where it was last assigned — a function return, a reassignment, or a loop variable taking each element.
- Decide which side is wrong: should the producer return the whole container, or should the consumer drop the
[...]? - Fix one side and re-run. If the value came from JSON or an API, print
type(value)at every step out of the data until the mismatch appears.
How to verify the fix
scores = [72, 88, 91]
print(type(scores), scores[0]) # <class 'list'> 72
score = scores[0]
print(type(score)) # <class 'int'> — score[0] would fail
A one-line type() check next to the failing line is the fastest verification: the [ ] should sit on a list, str, tuple or dict — never on an int.
Related messages worth knowing
- TypeError: the parent guide — every famous wording of this exception on one page.
- TypeError: int object is not iterable — the sibling message when a
forloop meets the same number. - TypeError: list indices must be integers — the mirror image — subscripting a list with a string instead.
Fix it interactively
These free problems practice the exact skill this error demands — knowing what type is in front of the bracket. Repair them in the browser, no setup:
Practice more Python bugs →🇮🇳 Hindi में समझें
इस error का मतलब है: जिस value पर आपने [ ] लगाया, वह एक single number (int) है, list या string नहीं। Python में int container नहीं है। x[0] लिखने से पहले check करो कि x में असल में क्या है: print(type(x))। 90% मामलों में वजह यही होती है कि variable कहीं और एक number से overwrite हो गया, या function पूरी list की जगह एक element return कर रहा है।