3.1 Hello world

Programming languages are traditionally introduced with a trivial example that does nothing more than write the words Hello world on the screen. The intention is to illustrate the essential components of the language, and familiarise the user with the details of entering and running programs.

The good news is that in Python this is an extremely simple program:

    print "Hello world"

The program is self-explanatory: note that we indicated what we wanted to print to the screen by enclosing it in quotation marks.

EXERCISE 3.1
Start up Python's interactive interpreter (see Chapter 2, ``Using the system'', for more details). Get Python to say ``Hello world'' to you by typing the above command, followed by the Return key (this tells Python you have finished that instruction). If you have trouble getting a Python prompt, or get an error message when your program is run, ask a demonstrator.

The disadvantage of the Python ``Hello world'' program being so simple is that we haven't learnt much about the language! The next section contains a more instructive example.