Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Reading Tracebacks & Common Errors

12 min 25 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 1 of 5 · View course roadmap
Step 1

Learn the idea

Errors are not failures: they're Python telling you exactly what went wrong. Read a traceback bottom-up: the last line names the error, the lines above show where.

The big five you'll meet constantly:

  • SyntaxError: Python can't even parse it (missing colon, unclosed quote)
  • NameError: using a variable that doesn't exist (often a typo)
  • TypeError: wrong type: "age: " + 25
  • IndexError / KeyError: missing list position / dict key
  • ValueError: right type, bad value: int("hello")

Pro habit: read the error name and message first, then the line number. 90% of bugs are solved by actually reading the message.

Where you'll use this

Reading tracebacks fast is the highest-leverage debugging skill: seniors resolve in seconds what juniors google for an hour, purely by reading the last line first and walking the stack.

Common mistakes

  • Reading only 'something went wrong' and re-running unchanged code: the message literally names the problem and line.
  • Fixing the traceback's top frame: the deepest frame (bottom) is where it actually raised; upper frames are just the call path.
  • Shipping code with silent failure paths because an error 'went away': understand why before moving on.

Pro tip

Paste the final line of any traceback into a search engine verbatim: TypeError: can only concatenate str (not "int") to str has been solved a million times. That's not cheating; it's the professional workflow.

Step 2

Try it yourself

Blank · autosaved

The lesson example is loaded and ready: press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.

PYexample.py
⌘ + Enter to run
Output appears here…
Step 3

Pass the challenge +25 XP

Blank · autosaved

The starter code contains two bugs. Fix them so it prints Total: 30.

Target output
Total: 30
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. int("abc") raises which error?
2. Where in a traceback is the actual error named?
Last step

Your notes (saved on this device)

Tip: use ← and → to move between lessons, ⌘K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path