Read the Error Message
The error message is trying to tell you exactly what went wrong and where โ but only if you actually read it. Learning to decode a traceback is a superpower most beginners skip.
Beginners' most common debugging mistake is astonishingly simple: they don't read the error message. They see red text, panic, and start changing things at random. But that error message is a precise report of what went wrong and where - often it tells you the answer directly. This session teaches you to actually read it: the traceback, the error type, and the line number.
Anatomy of an error
A Python error (a 'traceback') has three parts worth reading: where it happened, what type of error, and a message. Read from the bottom up.
Traceback (most recent call last):
File "shop.py", line 12, in <module>
total = price * quantitiy
NameError: name 'quantitiy' is not definedNameError: name 'quantitiy' is not defined - a typo (quantitiy). Right above it, the traceback shows the exact file and line (line 12) and the code involved. That's the whole answer: what went wrong (an undefined name), where (line 12), and the clue (a misspelling). The error didn't just fail - it told you precisely where to look and what to fix.Common error types, decoded
A handful of error types cover most of what you'll meet. Recognising them tells you what kind of mistake to look for.
| Error type | Usually means |
|---|---|
| NameError | A typo, or using something before defining it |
| TypeError | Wrong kind of value (e.g. adding text to a number) |
| IndexError / KeyError | Asking for an item that isn't there |
| SyntaxError | The code isn't valid Python (missing :, ), quote) |
| IndentationError | Wrong or inconsistent indentation |
You don't need to memorise these - just know the error type is a strong hint about the category of mistake. 'TypeError' points you at values and types; 'KeyError' points you at a dictionary key that's missing. The type narrows your search enormously.
Let the error guide you
- Actually read it - most beginners skip this and change things at random.
- Read the last line first - it names the error type and the problem.
- Use the line number - the traceback points at exactly where to look.
- The error type is a hint - NameError = typo, TypeError = wrong value, KeyError = missing key.
๐ฏ Key takeaways
- The most common beginner mistake is not reading the error message - which usually contains the answer.
- A traceback tells you three things: where it happened (file/line), the error type, and a message.
- Read the last line first - it names the error type and describes the problem.
- The error type is a strong hint: NameError = typo, TypeError = wrong value, KeyError/IndexError = missing item.
Frequently asked
The traceback is long and confusing - which part do I actually look at?
Start at the very bottom and work up - that's the key trick that makes tracebacks far less intimidating. The last line is the most important: it states the error type (like NameError or TypeError) and a message describing what went wrong, which is often the answer or very close to it. Just above that, the traceback shows the exact file and line number where the error occurred, along with the offending line of code - so you know precisely where to look. The middle of a long traceback shows the chain of function calls that led there (function A called B, which called C, where it broke); early on you can usually ignore that chain and focus on the bottom, because the failure is at the deepest point. As a rule: read the last line (what and why), then the line number just above (where), and go fix that spot. Only dig into the earlier call chain if the fix isn't obvious at the failure point and you need to understand how the code got there. The length is intimidating, but the two or three lines at the bottom carry almost all the useful information.
What if I read the error message and still don't understand it?
That's normal and fine - understanding error messages is itself a skill that grows, and there's a reliable next step: search for it. Copy the error type and message (like 'TypeError: can only concatenate str (not int) to str') and paste it into a search engine. Because millions of programmers have hit the same errors, you'll almost always find clear explanations and examples - often on sites like Stack Overflow - of what that error means and what typically causes it. This isn't cheating or a sign of weakness; looking up errors is something professional programmers do constantly, every single day. As you do it, you'll gradually build an intuition for common errors and need to search less. A good process is: first read the error carefully and look at the line it points to (often that's enough); if it's still unclear, search the exact message; and if you're still stuck, simplify the situation (which the next sessions cover) to see the error in isolation. The message plus a search engine resolves the large majority of errors, even ones that look baffling at first. Not understanding an error immediately is expected - knowing how to find out is the actual skill.
Related lessons
Errors Are Normal (and Useful)
Every programmer, from beginner to expert, spends much of their time with broken code. Theโฆ
Debugging & Problem-SolvingPrint, Trace, and See What's Happening
Not every bug announces itself with an error โ sometimes code runs fine but does the wrongโฆ
Debugging & Problem-SolvingCommon Bugs and How to Spot Them
A surprising amount of debugging is pattern recognition โ the same handful of mistakes cauโฆ