IndexError Python Origin: Application & API Last updated 15 Oct 2026

IndexError: list index out of range

Code accessed a list position that doesn’t exist.

Exact message you may see list index out of rangetuple index out of rangestring index out of range
Seen on: Python

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

  1. Check length before indexing
  2. Iterate directly: for item in items
  3. Use x[-1] for the last item
  4. Guard: parts[3] if len(parts) > 3 else None

Detailed fix by platform

Python

  1. first = items[0] if items else None

How to diagnose

  1. Index — Which index and list length?
  2. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

ArrayIndexOutOfBoundsException — java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5 (Java)ArrayIndexOutOfBounds…AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrorConnectionRefusedError — ConnectionRefusedError: [Errno 111] Connection refused (Python)ConnectionRefusedErrorEvent loop is closed — RuntimeError: Event loop is closed (Python)Event loop is closedkey is not a prop — Warning: `key` is not a prop. Trying to access it will result in `undefined` being returned. (React)key is not a propStringIndexOutOfBoundsException — java.lang.StringIndexOutOfBoundsException: begin 0, end 10, length 5 (Java)StringIndexOutOfBound…unique key prop — Warning: Each child in a list should have a unique "key" prop (React)unique key propIndexError

Explore the map of this error Full error map →

🧠 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.