Tuesday, July 7, 2009

python tuple

# A python tuple is enclosed in paranetheses ()
# tuples are immutable, which means once created they can't be
# added to or removed from like lists
>>> a = (1, 2, "three", 4)
>>> a
(1, 2, 'three', 4)

# the number of elements in a tuple
>>> len(a)
4

# take a slice of a tuple
>>> a[1:3]
(2, 'three')

No comments:

Post a Comment