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?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
yes. sequence doesn't have the 54th item.
The Way Python Indexing Works Is That It Starts At 0. So Your First Number Of Your List Would Be [0]. You Would Have to Print[52] as the first one is 0 and line 53 is [52].
Minus 1 And You Should be Fine :)
If you have a list with 53 items, the last one is
thelist[52]
because indexing start at 0.That's right. 'list index out of range' most likely means you are referring to
n-th
element of the list, while the length of the list is smaller thann
.Yes,
You are trying to access an element of the list that does not exist.
Have you got an off-by-one error?
Always keep in mind when you want to overcome this error, the default value of indexing and range starts from 0, so if total items is 100 then l[99] and range(99) will give you access up to the last element.
whenever you get this type of error please cross check with items that comes between/middle in range, and insure that their index is not last if you get output then you have made perfect error that mentioned above.
keep coding...