Python

  1. Home
  2. Computing & Technology
  3. Python

"Hello, World!": A Quick Tutorial on Python

By Al Lukaszewski, About.com

1 of 6

Introducing "Hello, World!"

The simplest program in Python consists of a line that tells the computer a command. Traditionally, the first program of every programmer in every new language prints "Hello, World!". 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':

#!/path/to/python
Be sure to give change the permission on the file to allows execution, if necessary for your operating system.

Now, let's take this program and embellish it a bit.

1 of 6

Explore Python

More from About.com

Python

  1. Home
  2. Computing & Technology
  3. Python
  4. Beginning Python
  5. Python "Hello World" Tutorial - "Hello, World!": A Quick Tutorial on Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.