You are here:About>Computing & Technology>Python> Beginning Python> Python "Hello World" Tutorial - "Hello, World!": A Quick Tutorial on Python
About.comPython
Newsletters & RSSEmail to a friendSubmit to Digg

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

From Al Lukaszewski,
Your Guide to Python.
FREE Newsletter. Sign Up Now!

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. Introducing "Hello, World!"
  2. Importing Modules and Assigning Values
  3. A Class Called Felicitations
  4. Defining Functions
  5. The main() Thing
  6. Tying It Up With a Bow

Previous | Next >>

 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.