ProjectStack
python

TypeError: 'NoneType' object is not subscriptable

You're trying to use square bracket indexing (like result[0] or data['key']) on a value that is None. A function or expression you expected to return a list, dict, or string returned None instead.

Common causes

  • A function that modifies a list in place (like list.sort() or list.append()) returns None
  • A function call returned None because it hit a code path with no return statement
  • A database or API query returned None when no record was found
  • You assigned the return value of an in-place method: result = my_list.sort()

How to fix it

  1. Print the value before indexing to confirm it's what you expect: print(result)
  2. Check functions that modify lists in place — they return None: use my_list.sort() then use my_list
  3. Add a None check before indexing: if result is not None: print(result[0])
  4. Ensure functions that should return data have a return statement on all code paths

Example

Traceback (most recent call last): File "app.py", line 4, in <module> print(items[0]) TypeError: 'NoneType' object is not subscriptable

Calling items = my_list.sort() and then indexing items[0] — sort() returns None

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.