TypeError: 'NoneType' object is not subscriptable
The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None. This means that you tried to do:
NoneType is the type of the None object which represents a lack of value, for example, a function that does not explicitly return a value will return None .
you will get the error message :
list1 = list.sort(list1) : - here, you are setting it to None. None always has no data and can not be subscriptable.
In order to correct this error this should be
In general, the error means that you attempted to index an object that doesn't have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. This is a design principle for all mutable data structures in Python.
This TypeError is the one thrown by python when you use the square bracket notation object[key] where an object doesn't define the __getitem__ method . You can reproduce TypeError that you get in your code if you try this at the Python command line:
The Typeerror may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be. Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError , but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError .
So you would get a TypeError if you tried list1 = list.sort(list1) because here you are setting it to None . None always has no data and can not be subscriptable.
Object is not subscriptable
A subscriptable object is any object that implements the __getitem__ special method (think lists, dictionaries). It is an object that records the operations done to it and it can store them as a "script" which can be replayed.