Debugger tool
Most IDEs (Integrated Development Environments) like Visual Studio Code have a tool called a “debugger” to help you identify and resolve bugs. Especially as we continue to write more complex programs, it is important to know what is in memory (the values of variables) and how the program control moves through your code. The debugger is an incredibly powerful and useful tool that allows us to dynamically interact with Python’s execution of a program, pausing at breakpoints to gain control. There is a bit of a learning curve to working with the debugger, but (like anything) comfort comes with practice and increased familiarity!
Tips for Using Breakpoints with the Debugger
Choose where to set breakpoint(s)
You may some idea of what is causing the bug
A variable
A block of code
Set breakpoint(s)
Before a variable is assigned
At the beginning of a block of code
Run the debugger → pause at the breakpoint
Examine the current state (variable values)
Use controls to incrementally move program control
Step over: move line by line
Step into: descend into the body of a function invocation
Step out: back out from the body of a function
Repeat until…
You have enough info to Stop the debugger & Modify your code
And… repeat this entire breakpoint process if there are still bugs!
Notes:
You can set multiple breakpoints
Use the Play button to resume code execution until next breakpoint