Printing out a list item by item


`In printing out a list item by item.What does the error "list index out of range" means?


Let us assume that this is our list:

x = ["a", "b", "c"]

Elements of list x are "a", "b", "c". Corresponding indices are: 0, 1, 2.

So, for example, to access element "b" we can use x[1], right?

Error list index out of range indicates that you have tried to access an element at the index that does not exist.

For our exemplary list x it might be index 3:

>> print x[3]
IndexError: list index out of range

Because as we stated before, valid indices for our list are 0, 1 and 2.

To spot the problem check all the places where you are getting value of the element of the list by index.


Thank you! I used len(n) instead of len(x).now its correct:relaxed:


Great! You're very welcome :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.