Your code ran fine yesterday, and today Python stops with TypeError: 'int' object is not subscriptable. This error sounds technical, but the idea behind it is simple once someone explains what “subscriptable” means. In this guide you will learn what triggers the error, how to find the exact line causing it, and the right fix for the most common scenarios, including the classic beginner case of trying to pick a digit out of a number.
Quick Answer
The error means you used square brackets, such as value[0], on an integer. Integers do not support indexing because a number is a single value, not a container of items. To fix it, check what type your variable actually holds at that line. If you need a digit from a number, convert it to a string first with str(number)[0]. If the variable was supposed to be a list, find where it was overwritten by an integer earlier in the code.
What “Subscriptable” Means
In Python, a subscript is the value inside square brackets. When you write names[0], you are asking for the first item of a container. Lists, strings, tuples, and dictionaries are subscriptable because they hold multiple values. An integer like 42 is a single whole value. There is no first item inside it, so Python raises a TypeError when you try.
Here is the error in its simplest form:
age = 25
print(age[0])
Python complains because age holds the number 25, not a sequence. Compare that with a string, which works fine: age_text = "25" followed by print(age_text[0]) prints the character 2. The difference between a number and text that merely looks like a number is the heart of this error.
The Three Usual Causes
You converted input to int and then tried to index it
A very common beginner pattern is reading a number and then trying to take its first digit:
number = int(input("Enter a number: "))
first = number[0]
The conversion to int destroyed the text form, so indexing fails. Keep the input as a string for digit work, or convert back with str(number)[0]. Our guide on reading user input as a number instead of a string explains when to convert and when to keep text as text.
A variable was overwritten by an integer
Maybe scores started as a list, but somewhere you wrote scores = sum(scores) or reused the same name for a counter in a loop. From that line onward, the name holds an integer, and any later scores[0] fails. Search your code for every assignment to that variable name.
A function returned an int instead of a list
Functions such as len(), sum(), count(), and index() return numbers. If you stored that result and then treated it like the original list, Python objects. Check what each function returns before chaining operations onto it. The Python built-in functions documentation lists the return type of every built-in.
How to Fix It Step by Step
- Find the line. The traceback ends with the failing line number. Open that line and identify which variable is inside the square brackets.
- Print the type just before the error. Add
print(type(variable))andprint(variable)on the lines above. Run again and confirm the value is really anintand see what number it holds. - Decide what you actually wanted. If you wanted a digit or character, convert:
str(variable)[0]gives the first character. If you wanted an item from a list, the variable holds the wrong thing, so continue to the next step. - Trace the variable backwards. Read upward through your code and find every place the variable is assigned. Look especially for loops that reuse the name, and for results of
len(),sum(), orint()stored in the same name. - Rename one of the two. Give the number its own name, such as
total_scores, and keepscoresfor the list. Clear names prevent this entire category of confusion. - Remove the debug prints and run the full script. Confirm the original task now works from start to finish, not just past the old error line.
Working With Digits of a Number the Right Way
If your real goal is digit work, you have two clean options. The string route is shortest: digits = str(2026) gives you text you can index, slice, and loop over, converting each piece back with int(digit) when you need maths. The maths route uses division and remainder: number % 10 gives the last digit and number // 10 drops it. Choose the string route for reading digits left to right, and the maths route when you process a number without caring about its length.
Common Mistakes to Avoid
- Wrapping the number in brackets to make it a list by force. Writing
[age][0]silences the error but hides the real bug in your logic. - Assuming input() returns a number. It always returns a string until you convert it, and converting removes your ability to index digits.
- Reusing short names like
xfor different things. One letter ends up meaning a list in one place and a count in another. - Indexing the result of len().
len(items)[0]never works; store the length and the list separately.
The Same Error With Other Types
Once you understand the int case, the whole family makes sense, and Python phrases them identically. 'float' object is not subscriptable arises the same way, for instance indexing a price or a measurement. 'NoneType' object is not subscriptable appears when a function that was supposed to return a list returned nothing instead, and you indexed the empty result. 'builtin_function_or_method' object is not subscriptable is the odd one beginners find baffling: it usually means you forgot the parentheses on a method or function, writing something like items.append[0] instead of items.append(0), so Python tried to index the method itself.
In every variant, the debugging move is identical: print the variable and its type immediately before the failing line, decide what you believed it was, and then trace back to the assignment that made it something else. The type named in the error message is Python telling you the truth about your data. Beginners often search the web for the exact phrase of their variant, but the fix is never variant-specific — it is always “this variable holds a different kind of value than the brackets require,” and the remedy is always in how that value was produced.
Conclusion
'int' object is not subscriptable means square brackets were used on a whole number. Print the variable’s type, work out whether you wanted a digit, a list item, or a completely different variable, and then either convert with str() or fix the assignment that overwrote your list. With that habit, this error takes under a minute to solve.
Frequently Asked Questions
Which types are subscriptable in Python?
Sequences and mappings are subscriptable: strings, lists, tuples, ranges, bytes, and dictionaries. Numbers, None, and booleans are not, because they are single values rather than containers. If you ever need to check, call type() on the variable right before the line that fails.
Why did the same code work with input from a variable?
Probably because that variable held a string or list at the time. The error depends on the type at the exact moment the brackets are used, not on how the line is written. Any earlier conversion or reassignment changes what happens.
How do I get the last digit of a number?
Convert to text and use str(number)[-1], then int() if you need it as a number. Or use the remainder operator: number % 10 returns the last digit directly as an integer, which is the cleaner option inside calculations.
Can a function cause this error inside a library?
The traceback may pass through library lines, but the root cause is almost always the value you passed in. If a library function expects a list of numbers and you hand it a single number, the failure can surface inside the library even though the fix belongs in your code.
Is this the same as “object is not iterable”?
They are cousins. Not subscriptable means you cannot use square brackets on the value, while not iterable means you cannot loop over it. Both come from treating a single value as if it were a container, and both are fixed by checking the type of the variable involved.


Leave a Reply