How to Run a Python Program in VS Code – The best way of using code editors

  • Reading time:12 mins read

How to run a Python program in VS Code?

To successfully run Code in VS Code we first need to set up the Python development environment. The Python development environment includes Installing VS Code, Python extension and Python itself.


What is the Visual Studio Code used for?

VS Code is an open-source Integrated Development Environment that can be virtually used with any programming language.

Visual studio code can be downloaded by visiting this link and pressing the button Download for Windows.


How to run a Python program in vs code


Once we have successfully installed VS Code we should now proceed to install the Python extension. The Python extension for Visual Code studio can be installed from the Visual studio marketplace by pressing Ctrl + Shift + x and searching the word Python in the search bar at the top.

How to run a Python program in VS Code by using extensions

Select the extension with the highest number of downloads by Microsoft and press the install button.


How to run a Python program in vs code


Once we have installed the Python extension we can now proceed to write Python codes. The standard way of writing and running Python programs in Python is by using the green button at the far right corner of the IDE. Once the code is executed the output is displayed in the terminal at the bottom.


How to run a Python program in VS Code using Jupyter Notebook

Jupyter Notebooks are also a common way of running Python programs, especially in the Data Science domain.

This is because notebooks offer an easier way of importing libraries as well as running codes bit by bit so that developers can easily monitor the flow of their programs.

Now using the notebook extension we can also run notebooks within the Visual studio code. In a similar manner, we can install this extension by pressing the extensions tab and then typing the notebook at the top of the search bar. Click Install to install the extension.


How to run a Python program in vs code


We can run a print function in one of the cells to print out the string ‘Hello CodeBerry !’. To execute this cell we simply need to press the triangular button on the left side of the current cell.

When this cell is executed please note that unlike in the normal circumstances where the output is displayed in the terminal, in this case, we get the output underneath the cell.



We can also move to the next cell and create a new cell by pressing the plus sign with the label Code. This means that we can have code in multiple cells and execute them all.

For instance, we can have a variable called name in the first cell and print out the value of the variable in the second cell as shown below.


How to run a Python program in vs code


This is particularly easy when working on a data project since one is able to visualize what each section of code is doing.


This is how to run a Python program in VS Code in practice. If you’d like to see more programming tutorials, check out our Youtube channel, where we have plenty of Python video tutorials in English.

In our Python Programming Tutorials series, you’ll find useful materials which will help you improve your programming skills and speed up the learning process.

Programming tutorials

Would you like to learn how to code, online? Come and try our first 25 lessons for free at the CodeBerry Programming School.

Learn to code and change your career!





Not sure if programming is for you? With CodeBerry you’ll like it.