A searchable index of the Python errors beginners hit most — what they mean, why they happen, and how to fix them.
Paste your error message into your editor's search (or use Ctrl/Cmd+F on this page) and jump to the fix. Each entry links to a full, step-by-step walkthrough on pythonbeginner.help.
Python prints the last line of a traceback as the error type and message — read it bottom-up:
Traceback (most recent call last):
File "app.py", line 3, in <module>
print(items[5])
~~~~~^^^
IndexError: list index out of range
The error type (IndexError) tells you the category; the message (list index out of range) tells you the specifics. Find your type below.
| Error | Typical message | Common cause | Fix |
|---|---|---|---|
AttributeError |
'NoneType' object has no attribute 'x' |
Using the result of a function that returned None |
Fix → |
AttributeError |
'list' object has no attribute 'x' |
Calling a string/dict method on a list | Fix → |
AttributeError |
'str' object has no attribute 'x' |
Treating a string like a list or number | Fix → |
IndexError |
list index out of range |
Index ≥ length of the list | Fix → |
IndexError |
tuple index out of range |
Index past the end of a tuple | Fix → |
KeyError |
'somekey' |
Reading a dict key that doesn't exist | Fix → |
IndentationError |
unexpected indent |
A line is indented when it shouldn't be | Fix → |
IndentationError |
expected an indented block |
A block (after :) is empty or not indented |
Fix → |
ImportError |
No module named 'x' |
Package not installed or wrong name | Fix → |
ImportError |
cannot import name 'x' |
Name doesn't exist / circular import | Fix → |
FileNotFoundError |
[Errno 2] No such file or directory |
Wrong path or working directory | Fix → |
AssertionError |
(often blank) | An assert condition was False |
Fix → |
items = ["a", "b", "c"]
print(items[3]) # ✗ valid indexes are 0, 1, 2items = ["a", "b", "c"]
if len(items) > 3:
print(items[3]) # ✓ check the length firstuser = {"id": 1}
print(user["name"]) # ✗ key 'name' is missinguser = {"id": 1}
print(user.get("name")) # ✓ returns None instead of crashing
print(user.get("name", "Anonymous")) # ✓ with a defaultresult = my_list.sort() # sort() returns None, not the list
result.append(5) # ✗ result is Nonemy_list.sort() # ✓ sorts in place
my_list.append(5) # ✓ use the list itself- 📚 Full error library: pythonbeginner.help/errors
- 🧠 New to tracebacks? Start with the common errors beginner guide.
- 🏋️ Practice: python-beginner-exercises
Released under CC0 1.0 by pythonbeginner.help — use it however you like.