Program to print "Hello World" in Python

Next →

Hello World, is usually the "first program" a programmer writes when she (or he) starts learning a new programming language. This one-line program helps beginners to understand the new language, its structure and most importantly, test the new IDE, on which they will write and execute the programs. Here this article, I am going to show you how to write your first "Hello World" program in Python.

What is Python?

Let's start with a brief introduction of Python.

Python is a high-level programming language that is used to write programs that can be easily understood by humans and machines (computers). That's why it is so popular among programmers, especially beginners.

Python is an Interpreted and also an Object Oriented Programming (OOP) language.

When we say "interpreted", it means that it reads (or executes) the code line by line, without compiling the code (converting into Machine Language). The code in the program (.py file) is first converted into "bytecode" (.pyc file) and then it is executed by the "Python Virtual Machine" (or PVM). Therefore, it is also called an Interpreted bytecode language".

Note: There is also a popular believe that Python is both "Compiled" and "Interpreted" language. That is, it is first compiled and then interpreted. I guess, it makes sense, since Python "generates byte codes". I have mentioned this in the above paragraph.

Anyways. It was a brief introduction. Now lets prepare to write our first "Hello World" program.

Download and Install Python

Before you write your first program, you need to download and install python in your computer.

If you are using "Windows" operating system, you can go to Python Releases for Windows site and download the latest version (under Stable Releases).

Note: If you are a "Mac" user, you can download python from here.

You need an IDE (Integrated Development Environment)

This is important. After you have successfully downloaded and installed Python in your computer, you'll need an IDE or an Integrated Development Environment, where you can write your codes and execute it.

Now, there are many Python IDEs that are available. You need one, to write your first program. I'll give you two IDEs, which I have personally tried and tested.

The first is Visual Studio Code (popularly known as VS-Code) and second is PyCharm.

So, if you are beginner, I would recommend "Visual Studio Code". Its a lightweight, versatile and feature rich IDE for python development. It also comes with many useful extensions.

On the other hand "PyCharm" is cross platform IDE for python. It is compatible with Windows OS, Mac OS and Linux. This makes it an ideal choice for developers doing complex python programming.

I am going to show you how to write your first program using both the IDEs, VS-Code and PyCharm.

Python "Hello World" program in Visual Studio Code

Assuming you have downloaded and installed VSCode in your computer.

Now, launch or open VSCode editor. At the top left of the editor, find the Extensions view and click it (press Ctrl + Shift + X keys together). In the "Search Extension" box, type "python" and press Enter key.

Install python extension provided by Microsoft. It will be first on the list.

microsoft python extension

Create python file and write the script

From the File menu (top left), click "New File" (or press Ctrl + Alt + Windows + N keys), and select Python File.

select python file in vscode

Name the file "hello_world" and save it. It will be saved with file extension ".py".

Now write the below script.

print("Hello World")

At the right top corner of the IDE, you will see a "right arrow". That's the Run button. Take the mouse over it and click it. It will execute the program (your first program).

It will display or print the output "Hello World" in the Terminal window.

hello world program in python using vscode

Its a simple one-line program to start with. Be it JavaScript, Angular or .Net, this is the first program every new programmer usually writes.

The print() function

In the above program, I am using the print() function to write (print) the text. Remember, it is case sensitive. Its "print()" with lower case "p". It takes a parameter (argument), which can be a string value or an integer value. You can pass a variable as an argument too.

Its one of the many built-in functions in Python. You don't have end the script with "semi colon", it doesn't have to be inside a function etc. Python is known for its "simplicity".

Python "Hello World" program in PyCharm

Launch PyCharm. You can select an existing hello_world.py file (that we created using VsCode in the above example) or create a new file.

Create a Python project

You'll have to create a project first.

1) At the top right corner, click the "New Project" button. This will open the new project window.

2) In the new project window, select Pure Python. Add a name to the project and choose a location (where the project will be created).

3) Click the "Create" button.

create a new project in pycharm

It will open the project in its IDE.

Now, we'll create a Python file. Using PyCharm, you can create different types of files for different languages. Such as, JavaScript, HTML, SQL, TypeScript etc. We need to create a python file.

Right click the project, choose "New" followed by "Python File". It will ask to name the file. Name it "hello_world" and press the "Enter" key. You will that it created file named "hello_world.py" inside the "project folder" we just created.

create new python file in pycharm

Write the hello world program.

print("hello world")

Run the program by pressing Shift + F10 keys together or click the Run button (a green button that you can find on the top of the IDE).

That's it. If everything is done correctly, you will see the "hello world" message at the bottom of the IDE.

python hello world program in pycharm

Note: To select an existing ".py" file in PyCharm, you can simply "drag and drop" the file in the IDE.

Next →