NOETRION

Browse by topic

← All articles
LESSON 2 OF 4 · Python & data foundations
PYTHON BASICS · 7 MIN READ

Python lists vs tuples: when does the difference matter?

A practical guide to mutability, ordering, and choosing the right container in everyday code.

Lists and tuples both hold ordered collections of values. You can index them, slice them, and loop over them. The useful distinction is whether the collection itself should change.

Use a list when the collection changes

A list is mutable: you can append, remove, or replace its elements after creation. A growing set of observations is a natural list.

temperatures = [28, 30, 29]
temperatures.append(31)
temperatures[0] = 27
print(temperatures)  # [27, 30, 29, 31]

Mutability also means that two names can refer to the same list. If you need an independent copy, make one explicitly:

original = [1, 2, 3]
copied = original.copy()
copied.append(4)
print(original)  # [1, 2, 3]

Use a tuple for a fixed group of values

A tuple cannot have its elements reassigned or appended. It is a good fit for a record whose positions have stable meanings, such as a pair of coordinates.

point = (4, 7)
x, y = point
print(x, y)  # 4 7

A tuple can still contain a mutable object. The tuple prevents replacing that element; it does not freeze an inner list.

record = ('sample', [2, 4])
record[1].append(6)
print(record)  # ('sample', [2, 4, 6])

A quick decision rule

  • Will you add, remove, or replace items? Choose a list.
  • Is this a fixed group with a clear meaning for each position? A tuple is often clearer.
  • Do you need names for many fields? Consider a dictionary or a data class instead of a long tuple.

Try it: create a list of three quiz scores, add one score, then store the final (minimum, maximum) pair as a tuple.

Check your understanding

Which container fits values you plan to append to?

Choose one answer