TypeError: 'int' object is not subscriptable

#here’s my list:

a_list = [1, ‘a’, False, 3.14, None, 4<=5, [35, ‘omg list of list’,‘True’, False]]

I wanted to print: a, False, 3.14, None, True, True, False

so I entered the code as:

print(a_list[2:7[2:]])

but it returns an error: TypeError: ‘int’ object is not subscriptable

You cannot combine indexing in python like this, to get what you want you have to treat the inner array part separately, check the code below,

print(a_list[1:6] + a_list[6][2:])

Hope it helps,

1 Like