Skip to content

Debugging Python

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:

breakpoint()

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.


→ Here's my latest YouTube video

→ Get my Python Handbook
→ Get my Python Handbook

→ I wrote 17 books to help you become a better developer, download them all at $0 cost by joining my newsletter

JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list