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
- Print the value before indexing to confirm it's what you expect: print(result)
- Check functions that modify lists in place — they return None: use my_list.sort() then use my_list
- Add a None check before indexing: if result is not None: print(result[0])
- 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 subscriptableCalling 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.
