How to Run Python Code in VS Code: Step-by-Step Guide

If you're delving into the world of programming, you might be wondering how to run Python code in Visual Studio Code (VS Code). VS Code is a popular and versatile code editor that supports Python through extensions, making it a solid choice for Python development.

All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)

Before we dive into the specifics, ensure you have the official Python extension by Microsoft, which is easily installed from the Extensions view in VS Code. This extension provides intelligent code completion, linting, formatting, refactoring, unit tests, snippets, and more.

How To Run A Python Script
How To Run A Python Script

Setting Up Your Python Environment

Before you can run Python code, you need to set up your environment in VS Code. This involves configuring the interpreter and installing necessary packages.

the diagram shows how to use python and jypton in an application for programming
the diagram shows how to use python and jypton in an application for programming

The Python extension automatically detects installed Python environments, but you can manually configure it if needed. To do this, press Ctrl+Shift+P (Windows, Linux) or Cmd+Shift+P (macOS) to open the command palette, then type 'Python: Select Interpreter' and choose the desired Python version.

Creating and Running a Simple Python Script

30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast

Now that your environment is set up, let's create and run a simple Python script. Open the command palette again and type 'Python: Create New Python File'. Name your file and press Enter.

In your new file, write a simple Python script like this:

```python print("Hello, World!") ```

Save the file with a .py extension, e.g., 'main.py'. To run the script, press Ctrl+F5 (Windows, Linux) or Cmd+F5 (macOS). You should see the output "Hello, World!" in the integrated terminal at the bottom of the screen.

Wrong vs Right Python Code (Beginner Guide)
Wrong vs Right Python Code (Beginner Guide)

Using the Debugger

VS Code's debugger provides a wealth of features for testing and exploring your code. To set a breakpoint, click in the gutter (left-hand side of the editor where line numbers are displayed) next to the line of code you want to pause execution on.

Start the debugger by pressing F5 or by selecting 'Debug: Start Debugging' from the command palette. The debugger will stop execution at the breakpoint, allowing you to inspect variables and step through your code using the 'Debug' panel.

How to Check the Version of Python
How to Check the Version of Python

Integrating with Jupyter Notebooks

Jupyter Notebooks are an excellent way to interactively develop and document your Python code. VS Code supports Jupyter Notebooks through the 'Jupyter' extension, allowing you to edit, run, and manage notebooks directly from the editor.

an image of a computer screen with cats on it and the words, python list method
an image of a computer screen with cats on it and the words, python list method
Python Cheat Sheet for Beginners
Python Cheat Sheet for Beginners
Learn Python in 10 days
Learn Python in 10 days
🐍🦎
🐍🦎
Python Cheat Sheet for Beginners 2026 | Python Basics, Syntax, Loops, Functions & Variables
Python Cheat Sheet for Beginners 2026 | Python Basics, Syntax, Loops, Functions & Variables
How to Learn Python Coding Faster? Easy Tips for Beginners
How to Learn Python Coding Faster? Easy Tips for Beginners
Python Complete Roadmap 🐍💻
Python Complete Roadmap 🐍💻
30-Day Python Learning Roadmap for Beginners | Step-by-Step Coding Plan 2026
30-Day Python Learning Roadmap for Beginners | Step-by-Step Coding Plan 2026
While loop in Python Easy to learn 🤩
While loop in Python Easy to learn 🤩
Python vs Java – What REALLY Happens When You Run the Code?
Python vs Java – What REALLY Happens When You Run the Code?
Emojis in python
Emojis in python
5 Python Tricks That Will Save You Hours of Coding
5 Python Tricks That Will Save You Hours of Coding
Python Learning Path for Beginners 2026 🚀
Python Learning Path for Beginners 2026 🚀
R vs Python - 25 Coding Differences
R vs Python - 25 Coding Differences
a cheetah and a tortoise running side by side on the same page
a cheetah and a tortoise running side by side on the same page
Python Learning Path for Beginners 2026 🚀
Python Learning Path for Beginners 2026 🚀
Python vs JavaScript — What Should You Learn in 2025?
Python vs JavaScript — What Should You Learn in 2025?
Environment Variables vs Secrets in Python
Environment Variables vs Secrets in Python

To use Jupyter Notebooks, install the 'Jupyter' extension and follow the setup instructions. Once set up, you can create new notebooks and work with them just like you would in the Jupyter web interface, but with the benefits of VS Code's powerful editing features.

Running Cells and Managing Output

In your Jupyter Notebook, select a cell containing code and press Shift+Enter to run it. The output will be displayed directly below the cell. To manage outputs, use the 'Jupyter: Clear All Output Cells' command from the command palette.

You can also use the 'Jupyter: Run All Cells' command to execute all cells in the notebook, handy for previewing or testing your entire project at once.

Exploring Python development in VS Code can be a rewarding journey. Whether you're writing scripts, running debuggers, or interacting with Jupyter Notebooks, VS Code provides an ecosystem tailored to boost your productivity and creativity.

Related Articles

How To Run Python In A Web Browser Sample App Website Python Flask Web Application Sample With Sql Server Database Can You Make A Desktop App With Python Python Web Server Example Github Ai Code Python Generator Python Example Code With Main Spring Ai Sample Code Sample Datasets For Statistics Python Sample Pandas