TypeError: Object is Not Subscriptable

TypeError: 'NoneType' object is not subscriptable

Quick Answer

You are trying to use square bracket indexing on an object that does not support it, such as None or an integer. This usually means a function returned None when you expected a list or dict.

Why This Happens

Subscripting with [] only works on sequences (list, tuple, str) and mappings (dict). If you try to index into None or an int, Python raises this error. The most common cause is calling a method that returns None then indexing the result.

The Problem

data = [3, 1, 2]
result = data.sort()
first = result[0]

The Fix

data = [3, 1, 2]
data.sort()
first = data[0]

# Or use sorted():
result = sorted(data)
first = result[0]

Step-by-Step Fix

  1. 1

    Check the variable's value

    Add a print statement before the failing line to see what the variable holds.

  2. 2

    Trace back to the assignment

    Find where the variable was assigned. If it comes from a method that returns None, use the original object.

  3. 3

    Add a None check

    Add: if result is not None: first = result[0].

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free