Writing Hello World! Program In Python
 

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.

Previous Using grep command in Linux
Next Comments In Python
 

About author

You might also like

Programming 0 Comments

Comments In Python

The comments in a programming language are used to explain something in the source code. For example, it can be used to explain what a line of code or block

Programming 0 Comments

Best 7 Python IDEs And Code Editors

A code editor basically used to write and edit code it is usually lightweight and considered good for learning and small projects. Once you start writing code for larger applications

Programming 0 Comments

Python Indentation

An indentation or indent is an empty space at the beginning of a line that signals the start of a new logical block in a Python program. Many programming languages

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply