Python TypeError: 'NoneType' object is not subscriptable
A plain-words explanation of this Python message: what it means, the usual causes, and the steps that fix it.
The messageTypeError: 'NoneType' object is not subscriptable
Make the error yourself
Run with Python 3.14.10. This is the smallest example we could find that shows it.
Python program (main.py)
def first_word(text):
words = text.split()
print(words[0])
result = first_word("hello world")
print(result[0])Output (the real message)
Traceback (most recent call last):
File "main.py", line 6, in <module>
print(result[0])
~~~~~~^^^
TypeError: 'NoneType' object is not subscriptableWhy it happens
None is Python's value for "nothing". A function that has no return statement gives back None. Then result[0] tries to look inside nothing. In the broken example first_word prints the word but never returns it, so result is None.
The same message appears when a method that works "in place" is used as if it returned a value, such as sorted_list = my_list.sort(), or when a search function returns None for "not found".
How to fix it
- Find where the variable got its value. Print it just before the failing line:
print(result). - If it is
None, look at the function that produced it and addreturn value. - For in-place methods like
list.sort(), use the list itself afterwards or usesorted(...)which returns a new list. - If "not found" is possible, check
if result is not None:before using it.
The corrected version
Python program (main.py)
def first_word(text):
words = text.split()
return words[0]
result = first_word("hello world")
print(result[0])Output (the corrected version)
hHow to avoid it
Make every function either return a value or only do something, and name it to match (get_name returns, print_name prints).
Questions
What does 'subscriptable' mean?
An object is subscriptable when you can use square brackets on it, like a list, a dictionary, a string or a tuple. None is not.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.