A beginner-friendly guide to the most common Python errors β what they mean, why they happen, and how to fix them β with examples.
If you're new to Python or even an intermediate dev, chances are you've seen errors that left you scratching your head. This repo is your quick reference guide for:
- Understanding common Python errors
- Identifying their root causes
- Learning how to fix them effectively
| S.No | Error Type | What It Means | Example | How to Fix |
|---|---|---|---|---|
| 1 | SyntaxError |
Python can't understand the code syntax | if x > 5 |
Add : β if x > 5: |
| 2 | NameError |
Using a variable/function that doesnβt exist | print(score) |
Define it first β score = 10 |
| 3 | TypeError |
Wrong data type used in an operation | "Age: " + 25 |
Convert type β "Age: " + str(25) |
| 4 | ValueError |
Right type, but invalid value | int("abc") |
Use valid value β int("123") |
| 5 | IndexError |
Accessing an invalid list index | nums = [1,2,3]; nums[5] |
Check length before access |
| 6 | KeyError |
Dictionary key doesnβt exist | data['b'] |
Use .get() or check with in |
| 7 | AttributeError |
Object lacks the method/attribute | 5.append(10) |
Use correct object type β e.g., list.append() |
| 8 | ImportError / ModuleNotFoundError |
Python canβt find the module | import numppy |
Fix name / install β pip install numpy |
| 9 | ZeroDivisionError |
Division by zero | 10 / 0 |
Check denominator before dividing |
| 10 | IndentationError |
Improper code indentation | def f():\nprint("Hi") |
Use consistent spaces (4 spaces or a tab) |
You can:
- Bookmark this repo as your quick reference
- Copy-paste the error examples to test yourself
- Use it in your team onboarding or tutorials
- Expand it with your own examples and PRs
Found a weird error or want to add more examples?
- Fork this repo
- Add your error and explanation
- Submit a Pull Request β
MIT License. Use, modify, share freely.
Created by Kiran Kumar β SEO guy turned Python enthusiast π