How to run Python code in VSCode
Run Python file directly
-
Open VSCode and create a Python file:Open or Create a file ending with
.py
.
-
Write Python code: Write your Python code in the file.
-
Click the "Run" button or use the shortcut F5: This will run the file using the Python interpreter.
Use Terminal or Command Prompt
-
Open the built-in terminal or command prompt: In VSCode, press
Ctrl
~
(Windows/Linux) or Cmd
~
(Mac) opens the built-in terminal.
-
Navigate to the directory containing the Python files: Use the
cd
command to navigate to the directory containing the Python files.
-
Run the Python command: In a terminal or command prompt, enter the following command:
<code>python [文件名].py</code>
Copy after login
Use the debugger
-
Set a breakpoint: Left click the mouse on the line of code you want to debug.
-
Start the debugger: Click the "Debug" tab in VSCode or use the shortcut key F5.
-
Step through code: Use buttons in the debugger to step through code, such as "Step In" and "Step Over".
Other methods
Use extensions:
- Python Extension Pack: Provides auto-completion, syntax highlighting, debugging, etc. Function.
Use an external Python environment:
- Set up VSCode to use an external Python environment. This allows you to manage different Python versions and packages.
The above is the detailed content of How vscode runs code Python. For more information, please follow other related articles on the PHP Chinese website!