"Beginning Python" instead.">
  1. Computing

"Merry Christmas!": A Quick Tour of Python


1 of 7

Introducing "Hello, World!"

In the spirit of the season, I have here revised my "Hello, World!" tutorial to offer the appropriate holiday greetings of the three monotheistic religions in one of three languages. At the end of the tutorial, you will be able to feed it a line like

 ">./MerryChristmas.py susie christian french !" 
and it will reply
"Joyeux Noël, Susie!" As this tutorial is in lieu of the "Hello, World!" section, let's give honourable mention to that historic lesson. Start up your favorite editor and save the following into a file:
 print "Hello, World!" 

To execute this program, save it with a suffix of '.py' (e.g., HelloWorld.py) and type 'python' and the filename in a shell like this:

 > python HelloWorld.py 
The output is predictable:
Hello, World!

If you prefer to execute it by its name, instead of as an argument to the Python interpreter, put a "bang" line at the top. Include the following on the first line of the program, substituting the absolute path to the Python interpreter for '/path/to/python':

Be sure to change the permission on the file to allow execution, if necessary for your operating system.

Unlike the usual "Hello, World!" program that functions in plain text, or ASCII, our little program needs to output non-English character sets. To enable Unicode support in the program, we tell Python that the program is written in Unicode. Immediately after the bang line, add this:

 # -*- coding: utf-8 -*- 

Now, let's take this idea and embellish it a bit according to what I outlined above.

  1. About.com
  2. Computing
  3. Python
  4. Beginning Python
  5. "Merry Christmas!": A Quick Tour of Python

©2014 About.com. All rights reserved.