1. Computing

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

From , former About.com Guide

2 of 6

Importing Modules and Assigning Values

First, let's import a module or two:

 import re, string, sys 

Then let's define the addressee and the punctuation for the output. These are taken from the first two command line arguments:

 greeting = sys.argv[1] 
 addressee = sys.argv[2] 
 punctuation = sys.argv[3] 

Here, we give greeting the value of the first command-line argument of the program. The first word that comes after the program's name when the program is executed will be assigned using the sys module. The second word (addressee) is sys.argv[2], etc. (the program's name itself is sys.argv[0]).

  1. About.com
  2. Computing
  3. Python
  4. Beginning Python
  5. Python "Hello World" Tutorial - Importing Python Modules and Assigning Values

©2013 About.com. All rights reserved.