Skip to content
Home » IndexError: list index out of range

IndexError: list index out of range

When you try to retrieve an index from a sequence, such as a list or a tuple which doesn’t exist, then IndexError is raised.

Example:

list = [1,2,3]
print(list[5])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-16-dccdf47c4682> in <module>()
      1 list = [1,2,3]
----> 2 print(list[5])

IndexError: list index out of range

To resolve the “indexerror: list index out of range” error, ensure that you are not attempting to access an item in a list that does not exist. If you use a loop to access an item, be sure that the loop takes into account the fact that lists are indexed from zero.