TypeError: 'NoneType' object is not subscriptable
Updated
The Python error "'NoneType' object is not subscriptable" means you used [ ] on a value that is None. Where the None comes from, and the fix.
What you see
def find_user(users, name):
for user in users:
if user["name"] == name:
return user
users = [{"name": "ada", "email": "ada@example.com"}]
user = find_user(users, "grace")
print(user["email"])Traceback (most recent call last):
File "/home/me/project/main.py", line 8, in <module>
print(user["email"])
~~~~^^^^^^^^^
TypeError: 'NoneType' object is not subscriptableWhat it means
You used square brackets, as in user["email"] or rows[0], on a value that is None. None holds no items, so there is nothing to look up. "Subscriptable" means "supports []".
The line in the traceback is where the None was used, not where it came from. Read upwards to the last place the variable was assigned. In the example, find_user finds no "grace", falls off the end of the loop and returns None.
Why it happens
- A function that does not always return. A function that reaches its end without
returnreturnsNone, asfind_userdoes when no name matches. - Keeping the result of an in-place method.
items = items.sort(),items = items.append(x)andrandom.shuffle(items)all returnNone. The list changed, and you replaced it withNone. - A lookup that found nothing.
dict.get(),re.match(),os.environ.get()and many library calls returnNonewhen there is no match. - A variable set to
Noneup front and only filled in on some paths.
How to fix it
Decide what should happen when there is nothing, and check for it before indexing:
user = find_user(users, "grace")
if user is None:
print("no such user")
else:
print(user["email"])
If the method changes the list in place, call it on its own line, or use the version that returns a new list:
items.sort() # changes items, returns None
items = sorted(items) # returns a new, sorted list
When the None should never happen, say so at the source: raise LookupError(f"no user {name!r}") at the end of find_user gives a clearer error than the one you got.
How each Python version words it
| Python | Prints |
|---|---|
| 3.9–3.15 | TypeError: 'NoneType' object is not subscriptable |
Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.
The wording is the same on every version in the table. Python 3.11 and later also underline the expression that failed, which tells you which of several subscripts on one line was None.
Questions
Which line is actually wrong?
Usually an earlier one. The traceback points at the [ ]; the bug is where the variable got None. Put print(repr(user)) or assert user is not None just before the failing line, then move it up until you find the assignment.
What else is not subscriptable?
Integers, floats, functions and most objects without a __getitem__ method. len[x] instead of len(x) gives "'builtin_function_or_method' object is not subscriptable"; the fix there is round brackets.
Sources
- Built-in constants: None, Python documentation
- Data model:
__getitem__, Python documentation list.sort()returns None, Python documentation
Read on October 25, 2026.