As we started series on Python for beginners today we will continue on our third article. In last two article we have discussed
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
- Visual Studio Code
- Sublime Text 3
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
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
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:
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.
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
Fig5: Python – Running Python program from Visual Studio Code editor
Once we clicked on this command we will see output in Terminal window as
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 🙂
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.