Skip to content

Debugging Python

The Valley of Code

Your Web Development Manual

Debugging is one of the best skills you can learn, as it will help you in many difficult situations.

Every language has its debugger. Python has pdb, available through the standard library.

You debug by adding one breakpoint into your code:


You can add more breakpoints if needed.

When the Python interpreter hits a breakpoint in your code, it will stop, and it will tell you what is the next instruction it will run.

Then and you can do a few things.

You can type the name of any variable to inspect its value.

You can press n to step to the next line in the current function. If the code calls functions, the debugger does not get into them, and consider them “black boxes”.

You can press s to step to the next line in the current function. If the next line is a function, the debugger goes into that, and you can then run one instruction of that function at a time.

You can press c to continue the execution of the program normally, without the need to do it step-by-step.

You can press q to stop the execution of the program.

Debugging is useful to evaluate the result of an instruction, and it’s especially good to know how to use it when you have complex iterations or algorithms that you want to fix.

→ Get my Python Handbook
→ Get my Python Handbook
  • THE VALLEY OF CODE (+ PRO), your web development manual
  • I wrote 15+ free coding BOOKS, download them here
  • SOLOPRENEUR LAND the missing MBA for wannabe solopreneurs craving a life with more freedom, control, fulfillment and purpose (summer 2024)