IndexError in Python

Python Methods and Functions

Exception thrown when accessing an element at an out-of-range index.


Raised when trying to access an element sequences using an index out of the range supported by the sequence.

  my_list = [0] 
my_list [1] # IndexError: list index out of range
my_list ['1'] # TypeError: list indices must be integers, not str

Notes

When slicing, indexes are automatically coerced to the supported range.


If the index is not integer , an exception TypeError .





Tutorials