Python Debugger (Pdb) - Debug Python Code Online

Debug Python code online with Python Debugger (Pdb). Step through code, set breakpoints, and inspect variables. Free, fast, and easy to use.

Pdb

The Python Debugger (Pdb) is a powerful tool for debugging Python code. It allows you to step through your code line by line, inspect variables, and set breakpoints to understand the flow of execution and identify errors. Use Pdb to debug Python scripts and applications effectively.

Pdb Commands

Here's a quick reference to common Pdb commands:

[main]
name=pdb
desc=The Python Debugger
[cheats]
show help = (h)elp
quit the debugger = (q)uit
print the value of something = (p)print
arguments of the current function = (a)rgs
list lines sourounding the current line = (l)ist
display the file and line number of the current line = (w)here
execute the current line = (n)ext
step into fucntion called at the current line = (s)tep
Move up the stace trace = (u)p
Move down the stack trace = (d)own
execute until the function return is encountered = (r)eturn
create a breakpoint at the linenumber = (b)reak <lineno>
list breakpoints = (b)reak
execute until end of for loop = until
pretty print the value of something = pp
treat stmt as a Python statement = !stmt

Using Breakpoints

Breakpoints are essential for pausing execution at specific lines. Use the (b)reak <lineno> command to set a breakpoint at a particular line number. The debugger will halt execution when it reaches that line, allowing you to inspect the program's state.

Stepping Through Code

The (n)ext and (s)tep commands are used to move through the code. (n)ext executes the current line and moves to the next line in the same function. (s)tep steps into any function called on the current line.

Inspecting Variables

Use the (p)rint command to display the value of variables. For pretty printing, use pp. This helps you understand the values of variables at different points in your code.