Python throws the error, ‘function’ object is not subscriptable, when we try to index or subscript a python function. Only iterables like array, list, tuples, dictionaries etc. are allowed to be indexed.
Consider this example –
def iAmAFunction():
return ["Captain America", "Hulk", "Thor"]
print(iAmAFunction[1])
## Error: 'function' object is not subscriptable
PythonCopy
The above code will throw the error because we are trying to subscript a function iAmAFunction[1]
. Although this function is returning a list, but we cannot directly subscript it.
#python #error #python error #python-short