Python unsubscriptable

Theodor picture Theodor · Nov 8, 2010 · Viewed 78.7k times · Source

What does unsubscriptable mean in the context of a TypeError as in:

TypeError: 'int' object is unsubscriptable

EDIT: Short code example that results in this phenomena.

a=[[1,2],[5,3],5,[5,6],[2,2]]
for b in a:
    print b[0]

> 1
> 5
> TypeError: 'int' object is unsubscriptable

Answer

kichik picture kichik · Nov 8, 2010

It means you tried treating an integer as an array. For example:

a = 1337
b = [1,3,3,7]
print b[0] # prints 1
print a[0] # raises your exception