Basic Types (Tuples)

Tuples

     f = (2,3,4,5)                   # A tuple of integers
     g = (1,)                        # A one item tuple
     h = (2, [3,4], (10,11,12))      # A tuple containing mixed objects
     

Tuple Manipulation

     x = f[1]                        # Element access. x = 3
     y = f[1:3]                      # Slices. y = (3,4)
     z = h[1][1]                     # Nesting. z = 4
     

Comments

  • Tuples are like lists, but size is fixed at time of creation.
  • Can't replace members (said to be "immutable")
  • Why have tuples at all? This is actually a point of much discussion.
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 15
July 17, 2000, beazley@cs.uchicago.edu
>>>