Error guide · TypeError
TypeError: 'int' object is not subscriptable
You used square brackets on a value that has no items to pick from.
Example
score = 85 print(score[0])
What Python says
TypeError: 'int' object is not subscriptable
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
Square brackets pick an item by position from a list, string, tuple or dictionary. A number is a single value with no positions, so score[0] has no meaning. The error often means a variable holds a different type from the one you expected. The version 'NoneType' object is not subscriptable usually means a function returned nothing.
How to fix it
score = 85 print(str(score)[0])
Output: 8
Tips
- Print
type(score)to see what you really have. - To work with the digits of a number, convert it to text first with
str(). - If the message says NoneType, check that your function uses
return.