Hello World in Python

In this tutorial, we are going to

Download and Install Python
Set Our Path
Download and Install Notepad++
Create and run a hello world script

Let's get started.

Download and Install Python

Head across to http://python.org/ and click the Windows Installer link on the homepage.

Once that's downloaded, double-click the .msi to launch the installer.

Just click Next all the way through to accept the default values.

Set Your Path

The Path environment variable tells the system where to look for executables. We are going to tell it where to find Python, so that we can run Python from the Windows cmd prompt.

To do this,

  1. Click on the Start Menu
  2. Right-click on Computer
  3. Click on Properties

Click on Advanced system settings

and then Environment Variables

Find the Path System variable, and click Edit

The variable value field is a list of directories separated by semicolons.

Jump to the end of the list and enter the directory where Python is installed. If you just accepted the defaults when installing Python, this should be C:\Python27\

Click Ok to close the dialog.

Test This Works

  1. Open a cmd prompt by clicking the start menu
  2. Type cmd into the Search field
  3. Hit enter

In the cmd window that appears, type python and hit enter. If you've set up your path correctly, this will open a Python shell.

Type quit() and hit enter to exit.

Download Notepad++

We are going to use Notepad++ to create our python source-code files. To do so we need to download a copy of it.

Head over to http://notepad-plus-plus.org/download/v6.5.3.html and download the installer.

Once the installer has finished downloading, run it.

You can just click Next all the way through here to accept the defaults.

If you want to run Notepad++ from the Windows cmd prompt, then add the destination folder to the Windows path environment variable.

This is very similar to the steps in the Set Your Path section (above).

Once Notepad++ has finished installing, open it up.

Hello World

We are going to create a very simple Python script and then run it.

This serves 2 purposes:

  1. It ensures you have everything set-up correctly.
  2. It demonstrates how to run Python scripts

Create it

Click on File > New to create a new file in Notepad++

Either type in, or copy and paste the following code:

def main():
    print 'hello, world'

if __name__ == '__main__':

Save the file somewhere easy to find. I'd suggest creating a folder on your Desktop called python_tutorial.

I've given it the filename hello_world.py

By convention, Python source files end with a .py extension.

Run it

Navigate to the folder containing your script.

Shift + Right-click in that folder and select Open command window here

This open a cmd window and navigates to the location of the folder for you.

Type in the following command to run your script:

python hello_world.py

You should see the following output.


Getting your environment set-up can be daunting for python greenhorns.

We've covered a lot of ground. Go grab a coffee. We'll pick up here in the next tutorial.

Python Functions and If Statements

Please Share

If you found this useful, please share with friends.

comments powered by Disqus