Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VSCode Running and Debugging Code

VSCode Running and Debugging Code

VS Code has built-in support for running and debugging Node.js applications.

In this section, we will use the Python extensioninstalled in the previous partto debug a Python program.

Next, let us debug the hello.py program created earlier.

Before debugging, make sure Python 3 is installed on your computer.

If no Python interpreter is installed on your computer, a notification will pop up in the lower right corner of the window.

Select Select Interpreter to open the Command Palette, then choose the Python interpreter you want to use or install a new one.

Set breakpoints

In the hello.py file, place the cursor on the print line, click the small red dot (shown when the mouse moves over its position), or press F9 to set a breakpoint.

A red dot will appear in the left margin of the editor, indicating that a breakpoint has been set.

A breakpoint allows you to pause when the program reaches a certain line of code, facilitating debugging.

Start a debugging session

Press F5 to start a debugging session.

The system will prompt you to select a debugger; choose the Python debugger.

Select Run Current Python File:

Debug code

After the program starts, execution will pause at the breakpoint you set.

**Tip:** Hover the mouse over the name variable in the editor to view its value. In the Variables View of the Debug view, you can view variable values at any time.

Continue program execution

In the debug toolbar, click the Continue button, or press F5 again, to continue program execution.

VS Code provides many advanced debugging features, such as Watch Variables, Conditional Breakpoints, and Launch Configurations.