Alex Rivera | Logout

Does "IndexError: list index out of range" when trying to access the N'th item mean that my list has less than N items?

Asked 2009-07-08T15:03:55.890
53

I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?

Edit
Report

1 Answer

37

Yes,

You are trying to access an element of the list that does not exist.

MyList = ["item1", "item2"]
print MyList[0] # Will work
print MyList[1] # Will Work
print MyList[2] # Will crash.

Have you got an off-by-one error?

answered 2009-07-08T15:08:32.620

Your Answer