@@ -349,17 +349,31 @@ A tuple consists of a number of values separated by commas, for instance::
349349 ... u = t, (1, 2, 3, 4, 5)
350350 >>> u
351351 ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))
352+ >>> # Tuples are immutable:
353+ ... t[0] = 88888
354+ Traceback (most recent call last):
355+ File "<stdin>", line 1, in <module>
356+ TypeError: 'tuple' object does not support item assignment
357+ >>> # but they can contain mutable objects:
358+ ... v = ([1, 2, 3], [3, 2, 1])
359+ >>> v
360+ ([1, 2, 3], [3, 2, 1])
361+
352362
353363As you see, on output tuples are always enclosed in parentheses, so that nested
354364tuples are interpreted correctly; they may be input with or without surrounding
355365parentheses, although often parentheses are necessary anyway (if the tuple is
356- part of a larger expression).
357-
358- Tuples have many uses. For example: (x, y) coordinate pairs, employee records
359- from a database, etc. Tuples, like strings, are immutable: it is not possible
360- to assign to the individual items of a tuple (you can simulate much of the same
361- effect with slicing and concatenation, though). It is also possible to create
362- tuples which contain mutable objects, such as lists.
366+ part of a larger expression). It is not possible to assign to the individual
367+ items of a tuple, however it is possible to create tuples which contain mutable
368+ objects, such as lists.
369+
370+ Though tuples may seem similar to lists, they are often used in different
371+ situations and for different purposes.
372+ Tuples are :term: `immutable `, and usually contain an heterogeneous sequence of
373+ elements that are accessed via unpacking (see later in this section) or indexing
374+ (or even by attribute in the case of :func: `namedtuples <collections.namedtuple> `).
375+ Lists are :term: `mutable `, and their elements are usually homogeneous and are
376+ accessed by iterating over the list.
363377
364378A special problem is the construction of tuples containing 0 or 1 items: the
365379syntax has some extra quirks to accommodate these. Empty tuples are constructed
@@ -388,8 +402,6 @@ many variables on the left side of the equals sign as there are elements in the
388402sequence. Note that multiple assignment is really just a combination of tuple
389403packing and sequence unpacking.
390404
391- .. XXX Add a bit on the difference between tuples and lists.
392-
393405
394406.. _tut-sets :
395407
0 commit comments