IndexError: list index out of range
Code accessed a list position that doesn’t exist.
list index out of rangetuple index out of rangestring index out of range Meaning
Lists are zero-based; the last index is len(x) - 1. Empty results, off-by-one loops and split() returning fewer parts than expected are typical.
Common causes
- Empty list (no results)
- Off-by-one loop (range(len(x) + 1))
- line.split(',')[3] on a short line
- Modifying the list while iterating by index
⚡ Quick fix
- Check length before indexing
- Iterate directly: for item in items
- Use x[-1] for the last item
- Guard: parts[3] if len(parts) > 3 else None
Detailed fix by platform
Python
first = items[0] if items else None
How to diagnose
- Index — Which index and list length?
- Data — Why is the list shorter than expected?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Python
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026