Using the Interpreter Prompt 

A Byte of Python 

Go to the Table of Contents. Visit the Gifcom web site.

We will now see how to run a traditional 'Hello World' program in Python. This will teach you how to write, save and run Python programs.

There are two ways of using Python to run your program - using the interactive interpreter prompt or using a source file. We will now see how to use both the methods.

Using the interpreter prompt

Start the intepreter on the command line by entering python at the shell prompt. Now enter print 'Hello World' followed by the Enter key. You should see the words Hello World as output.

For Windows users, you can run the interpreter in the command line if you have set the PATH variable appropriately. Alternatively, you can use the IDLE program. IDLE is short for Integrated DeveLopment Environment. Click on Start -> Programs -> Python 2.3 -> IDLE (Python GUI). Linux users can use IDLE too.

Note that the <<< signs are the prompt for entering Python statements.

Example 3.1. Using the python interpreter prompt

$ python
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hello world'
hello world

Notice that Python gives you the output of the line immediately! What you just entered is a single Python statement. We use print to (unsurprisingly) print any value that you supply to it. Here, we are supplying the text Hello World and this is promptly printed to the screen.

How to quit the Python prompt

To exit the prompt, press Ctrl-d if you are using IDLE or are using a Linux/BSD shell. In case of the Windows command prompt, press Ctrl-z followed by Enter.