Python · Stage 5 – Grouping Data · Lesson 31 of 50

Tuples

Store an ordered group that should not be changed.

point = (4, 7)
Line-by-line explanation
  1. Round brackets create this tuple.
  2. The tuple contains two integers.
  3. point stores the pair.

Tuple indexing works like list indexing:

x = point[0]
Line-by-line explanation
  1. Index 0 selects the first item.
  2. x stores 4.

Tiny Practice

Read the second coordinate.

Starter template

point = (4, 7)
y = CHANGE_ME
Line-by-line explanation
  1. The tuple has two positions.
  2. The second position has index 1.
Hint
  1. Use point.
  2. Use square brackets for lookup.
  3. Put 1 inside.
Show Solution
point = (4, 7)
y = point[1]
Line-by-line explanation
  1. The tuple is created.
  2. Index 1 selects 7.
  3. y stores 7.