Python - First python program in Visual Studio Code using print()

Python for Beginners – Part 3 – First Python Program with Visual Studio Code

Hi All,

As we started series on Python for beginners today we will continue on our third article. In last two article we have discussed

What is Python? Why to learn Python?

Installing Python

In our today’s third article we will write our very simple first python program.

Choosing Python Editors:

To start writing Python program first thing we need to choose the code editor. There are several very good code editors are 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 here in comparison. There are very nice comparison  articles are available, couple of articles are referenced in “References” section

Since I am SharePoint / Office 365 developer, I’ll go with my all-time favorite IDE Visual Studio Code.

Python with Visual Studio Code:

If you also go with Visual Studio Code and not installed kindly please download and install from here

Once Visual Studio Code installed successfully to start with first program we need to install “Python Extension for Visual Studio Code”.  Python extension can be installed from multiple locations.

a. After starting Visual Studio Code from “Welcome” as

Python : Installing Python Support in Visual Studio Code

Fig1: Python – Installing Python Support 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 showing “Python support is already installed” message.

b. From editor itself. We will discuss this in below section “Writing first program“.

Writing first program:

  • Create the new file in Visual Studio Code, save it as “My First Python Program”, file will be saved with extension “.py”. All Python files have extension “.py” as
Python - Python file with extension ".py" in Visual Studio Code

Fig2: Python – Python file with extension “.py” in Visual Studio Code

  • Here if Python extension is not installed then at the bottom it asks for it as shown in below figure:
Python - Recommendation for Python extension installation from editor if it is not already installed

Fig3: Python – Recommendation for Python extension installation from editor if it is not already installed

So we can install Python Extension from here as well.

  • 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 below figure and we are done.  We are using print() to print the line.
Python - First python program in Visual Studio Code using print()

Fig4: Python – First Python program in Visual Studio Code using print()

  • To run this program just right click in Editor and click on “Run Python File in Terminal” as
Running Python program from Visual Studio Code editor

Fig5: Python – Running Python program from Visual Studio Code editor

Once we clicked on this command we will see output in Terminal window as

Python program output in Terminal Window of Visual Studio Code

Fig6: Python – program output in Terminal Window of Visual Studio Code

So this is our first Python program, in coming articles we will go in more depth 🙂

References:

Getting Started with Python in VS Code

Python in Visual Studio Code

12 Best Python IDEs and Code Editors in 2019

Python IDEs and Code Editors (Guide)

Python print() Function

Thanks for reading 🙂

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more.

If you have any suggestion / feedback / doubt, you are most welcome.

Stay tuned on Knowledge-Junction, will come up with more such articles.

Advertisements

Comments

4 comments on “Python for Beginners – Part 3 – First Python Program with Visual Studio Code”
  1. Hrishikesh Vibhute says:

    You can also try Jupyter notebook as it very handy for python coding.

    1. Yeah, that one is also good one. Thanks for sharing 🙂

  2. kiraninprogress says:

    Hi! What an informative and interesting post! I was wondering if you could checkout my new piece on ARTIFICIAL INTELLIGENCE & JOBS OF THE PAST!And I would really appreciate it if you could comment some feedback to improve the writing style. Looking forward to hearing from you. – Kiran

    https://kiranninprogress.wordpress.com/2019/12/04/artificial-intelligence-jobs-of-the-past/

    1. Thanks. I read through your article. Very well written. Thanks for sharing 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.