Writing Hello World! Program In Python


In the last few articles, we have installed python and set up VS code IDE on Linux and Windows for development using Python.

Today in this tutorial we will write and execute our first program in Python.

Write and execute your first python program using terminal

Follow the given steps to write and execute the hello world program using the terminal –

1. Press ctrl+alt+t to open the terminal on your system

2. Create a directory where you want to create python files by using mkdir command

For example –

mkdir python_dir

3. Move to created directory using –

cd python_dir

4. Create and open hello.py with a text editor –

nano hello.py

Please note that the .py extension is important. Now add the given line to this file

print ("Hello World!")

Where print() is a built-in python function Hello World is a string that can be enclosed using single or double-quotes. We will see functions and strings in Python in detail in the coming articles.

Now press ctrl+s to save and then ctrl+x to exit from the text editor.

5.  Execute the program using the python (In windows) or Python3 (In Linux or Mac)command –

python hello.py

or use –

python3 hello.py

This will display the output as given in the image below –

Create hello world program in Visual studio code

1. Create a directory lets say python_dir in your current working directory

mkdir python_dir

2. Right-click on the python_dir and open it with visual studio code.

3. Next create a file with the name hello.py write the given line in this file

print("Hello World")

Press ctrl+s to save this file.

4. Click on run this file by clicking on the green triangular icon given on the upper right side of the editor.

This will display the output on the terminal inside the IDE.

Now try this on your own system. If face any problem then write us in the comments below.

Leave a Comment

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