Learning Python - First Python Program With Visual Studio Code

In this article, we will discuss our basic "Hello World" first Python program using Visual Studio Code.

In the last two articles "Learning Python - Introduction To Python" and "Learning Python - Installation Of Python On Windows 10", we discussed the introduction to Python, why to learn Python, and how to install Python on Windows 10. 
In this article, we will write our first Python program. We will write a very simple Python program using Visual Studio Code. In order to start Python programming, the first step is to choose the code editor.

Choosing Python Editors

There are several very good code editors available like,
  1. PyCharm
  2. Spyder
  3. Visual Studio Code
  4. PyDev
  5. Idle
  6. Wing
  7. Vim
  8. Sublime Text 3
  9. Thonny
We can choose any editor of our choice, each IDE has its own PROS and CONS. We will not go into comparisons here. There are very nice comparison articles available; a couple of articles are referenced in the "References" section.
Since I am SharePoint/Office 365 developer, I'll go with my all-time favorite IDE, i.e., Visual Studio Code.

Python with Visual Studio Code

If you also go with Visual Studio Code, then please download and install it from here.
Once Visual Studio Code is installed successfully, to start with the first program, we need to install "Python Extension for Visual Studio Code". Python extension can be installed from multiple locations.
  • After starting Visual Studio Code from "Welcome" -
Installing Python Support in Visual Studio Code
Fig1: Python - Support for Python in Visual Studio Code
Here, as shown in above Fig1, from "Tools and languages" section, we can install support for various languages. Here, in my case, I already have Python extension installed so it is showing the "Python support is already installed" message.
  • From the editor itself, we will discuss this in the below section "Writing the first program".

Writing first program

  1. Create the new file in Visual Studio Code, save it as "My First Python Program", file will be saved with the extension ".py". All Python files have extension ".py" as,
    Python file with extension ".py"
    Fig2: Python - Python file with extension ".py" in Visual Studio Code
  2. Here if Python extension is not installed then at the bottom it asks for it as shown in below figure,
    Recommendation for Python extentsion installation
    Fig3: Python - Recommendation for Python extension installation from the editor if it is not already installed
  3. Let's write our first line of actual code. We will just print the line "Hello World - This is my first Python program" as shown in the below figure and we are done. We are using print() to print the line.
    First line of Python code
    Fig4: Python - First line of Python code with print()
To run this program, just right-click in Editor and click on "Run Python File in Terminal".
Running Python program from Visual Studio Code editor
Fig5: Python - Running Python program from Visual Studio Code editor
Once we click on this command, we will see the output in the Terminal window.
Python program output in Terminal Window of Visual Studio Code
Fig6: Python - Python program output in Terminal Window of Visual Studio Code
So this is our first Python program. In upcoming articles, we will go into more depth :)