Stop Using print(): Learn the VSCode Debugger
Overview
Debugging is more than just fixing errors; it is about understanding the execution flow of your software. Many developers rely on print() statements to inspect variables, but this approach is messy and inefficient for complex logic. The debugger allows you to pause time, inspect the entire state of your application, and step through code line-by-line without modifying the source files.
Prerequisites
To follow this guide, you should have installed on your system and a basic understanding of functions and variables. You will also need as your primary IDE.
Key Libraries & Tools
- Python Extension for VSCode: This is the essential bridge between the editor and the Python interpreter, providing linting, debugging, and IntelliSense.
- Python Debugger (debugpy): The default engine used to attach to your scripts.
- Framework-Specific Configurations: VSCode includes pre-built profiles for and .
Code Walkthrough
Setting Breakpoints
Breakpoints are the foundation of debugging. You set them by clicking to the left of the line number.
def process_author_scores(author_name, scores):
# Click the margin here to set a line breakpoint
avg = calculate_average(scores)
print(f"{author_name}: {avg}")
Conditional Logic and Function Breakpoints
Sometimes you only care about a specific state. Right-click a breakpoint and select Edit Breakpoint to add an expression. For example, author_name == "ArjanCodes" ensures the debugger only triggers for that specific case. You can also add Function Breakpoints in the Debug panel to stop every time a specific function is called, even if you don't have the file open.
Inspecting State
Once the code pauses, use the Call Stack to see the path the interpreter took. Clicking different levels in the stack reveals the local variables specific to that function's scope.
Syntax Notes
When using Conditional Breakpoints, the syntax follows standard Python boolean logic. You can use any variable currently in scope within your expression. In the Watch Panel, you can evaluate complex expressions like len(scores) > 0 which update in real-time as you step through the code.
Practical Examples
- Loop Debugging: Use a hit count breakpoint to stop a loop only after the 100th iteration to find an edge case.
- API Development: Use the configuration to debug incoming requests and inspect headers or body payloads mid-request.
Tips & Gotchas
- The 'Step Into' vs 'Step Over' Trap: Use Step Over (F10) to stay in the current function. Use Step Into (F11) if you want to dive into the internal logic of a called function.
- Save to Refresh: If you change code while debugging, you usually need to restart the session (Ctrl+Shift+F5) for the changes to take effect.
- 33%路 products
- 33%路 products
- 17%路 products
- 17%路 products

Stop Using print(): Learn the VSCode Debugger
WatchArjanCodes // 7:02
On this channel, I post videos about programming and software design to help you take your coding skills to the next level. I'm an entrepreneur and a university lecturer in computer science, with more than 20 years of experience in software development and design. If you're a software developer and you want to improve your development skills, and learn more about programming in general, make sure to subscribe for helpful videos. I post a video here every Friday. If you have any suggestion for a topic you'd like me to cover, just leave a comment on any of my videos and I'll take it under consideration. Thanks for watching!