TypeError
TypeError: 'NoneType' object is not subscriptable
Traceback
Traceback (most recent call last):
File "main.py", line 1, in <module>
result = print("hello")[0]
TypeError: 'NoneType' object is not subscriptableWhat causes this error
Bracket notation was used on an object that does not support indexing or key access. Common with None values from functions that return nothing, or with types like int, float, and bool.
How to fix it
Check the type of the object before subscripting. Watch for functions that return None (especially list methods that modify in-place). Use type() to debug unexpected None values.
Code that causes this error
result = print("hello")[0]Fixed code
message = "hello" print(message) first_char = message[0]
About TypeError
This error is raised when you use bracket notation (`obj[key]` or `obj[index]`) on an object that does not support subscripting — meaning it has no `__getitem__` method. The most frequent cause is calling a subscript on None, which happens when a function returns None unexpectedly. For example, list methods like `.append()`, `.sort()`, and `.reverse()` return None, so chaining `mylist.append(1)[0]` raises this error.
Other non-subscriptable types include integers, floats, booleans, and functions. In Python 3.9+, you might also see this when trying to use built-in types as generic types in annotations (e.g., `list[int]` works in 3.9+ but `List[int]` from typing is needed in earlier versions). The fix is to check the type of the object you are subscripting and ensure it actually supports indexing or key access.
Common scenarios
Performing operations between incompatible types like strings and integers
Calling methods that return None and chaining operations on the result
Passing the wrong number or type of arguments to a function
Using bracket notation on objects that do not support indexing