1. Home
  2. Computing & Technology
  3. Python

Beginning Python: Data Types

From Al Lukaszewski, for About.com

9 of 10

Tuples

In Python, a tuple may be defined as a finite, static list of literals (numeric or string). For our purposes, a tuple is very similar to a list in that it contains a sequence of items. It differs from a list in that it cannot be changed once it is created. One can index, slice and concatenate, but one cannot append or alter the values of the tuple after it has been initialized.

To initialize a tuple, one encloses the values in parentheses and separates them by commas.

directions = ('north', 'south', 'east', 'west')
coordinates = (45, 34, 48, 32)
print directions[3]
print coordinates[1]
output:
west
34

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python

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

All rights reserved.