Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985- 1990. Like Perl, Python source code is also available under the GNU General Public License (GPL).

Let us look at some simple hello world examples to get you started with this beautiful language.

Example 1: Hello World Python

This example project will teach you the following concepts:

  1. Introduction to Python
  2. Create python project and run it.

Step 1: Create Project

The first step is to create a Python project directory for this example.

Creating a Project Directory and Files

Open a terminal and enter the following commands to make a projects directory and an inner directory for this example within that projects directory.

For Linux, macOS, and PowerShell on Windows, enter this:

$ mkdir ~/projects
$ cd ~/projects
$ mkdir your_example_name
$ cd your_example_name

For Windows CMD, enter this:

> mkdir "%USERPROFILE%\projects"
> cd /d "%USERPROFILE%\projects"
> mkdir your_example_name
> cd your_example_name

Then create your file inside that directory.

Coding via IDLE

If you don't want to create project files and want to code directly in the IDLE then invoke the IDLE as follows:

For Unix/Linux:

$python

or

python% # Unix/Linux

For Windows:

C:> python # Windows/DOS

Step 2: Dependencies

No dependencies are needed for this project.

Step 3: Write Code

Create a file named main.py and add the following code:

print "Hello World!\n"

Yeah, that is the only code you need to write a hello world program in python.

If you run the code you will get the following:

Hello World!

Run

Save the code and run your code as follows:

Assuming our file name or python script is main.py, run it as below.

For Unix/Linux:

$python main.py

Or

python% main.py # Unix/Linux

And for Windows:

C: >python main.py # Windows/DOS

You can also use an IDE like IDLE, PythonWin , Visual Studio Code or PyCharm.