Home > Objects -> Tuple


Definition: A tuple refers to a sequence of objects separated by commas and enclosed by parentheses.

  • Remember: a list is a sequence of objects separated by commas and enclosed by brackets.
  • Example: An ordered pair (-1,2) is a 2-tuple.
  • So far, I have only seen tuples used as ordered pairs in graphics commands such as point.
  • The j-th element of a tuple is extracted as with lists, i.e. tuple1=(-1,2); tuple1[1] is 2. See: Operations on Lists
  • The object tuple is different from the command tuples. (This is the reason for the non-plural name of this page.)
  • To turn a tuple into a list, use the command list, i.e. list(tuple1).

Jan2013: Tuples are also sequences and are similar to lists except they are immutable. They are created using a pair of parentheses instead of a pair of square brackets and being immutable means that once a tuple object has been created, it cannot grow, shrink, or change the objects it contains. Reference: Sage for Newbies, Ted Kosan, pp. 40.


Keywords: sage, tuple, lists