Write Python. Understand every error.

Open the editor

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.

Try this code in Py-CRAFT

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

Learn the ideas behind it

Other common errors

Share this page: