Python 3.2Code walkthrough8 parts

Tuples

Use fixed-size immutable records, and unpack them.

Loading your progress…Next: 3.3 Sets

In this lesson8 parts

  1. 01A pair of values that should not change
  2. 02Creating and reading a tuple
  3. 03What immutable means
  4. 04The comma makes the tuple
  5. 05Packing and unpacking
  6. 06Unpacking in a for loop
  7. 07A tuple that holds a list
  8. 08Recap, your challenge, and next

Key terms

The words this lesson introduces, each in one line. The module’s glossary collects them all.

immutable
An object that can not be changed after it is created: a tuple, a string, a number.
packing
Collecting several values, separated by commas, into one tuple: point = 12.9716, 77.5946.
tuple
An ordered sequence of values, written with commas, that can not be changed: (12.9716, 77.5946).
unpacking
Binding each item of a sequence to its own name, in order: lat, lon = point.

Quiz 5 questions

Your first pick on each question is the one that counts, and a right one earns a coin. Getting one wrong here is how the lesson sticks.

Practice

Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.

The self-checking notebook for this lesson is Notebook 1 · Lists and Tuples.

Common mistakes

What you will see when it goes wrong, why it happens, and the fix.

Where it’s used

Where this lesson’s ideas turn up in real work.