NOETRION

Choose a topic

LESSON 2 OF 9 · Python & data foundations
PYTHON BASICS · 4 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. You can read an item by its position, select a slice, or iterate over the items. Choosing between them becomes easier when you ask a practical question: should this collection's membership or order change while the program runs?

We will use a study planner. A list holds the tasks you are still editing. A tuple groups the fixed parts of one scheduled session. The examples use Python 3.12. They are about program behavior, not a claim that one container is always faster.

Use a list for a collection you edit

tasks = ["Read notes", "Solve problems", "Check answers"]
tasks.append("Review mistakes")
tasks[0] = "Recall yesterday's notes"
print(tasks)

append() adds an item at the end. Assignment to index zero replaces the first item. The data structures tutorial describes these list operations. A list's mutability is useful here because editing the plan is part of the task.

An index describes a position, not an item identity. After you insert or remove an earlier item, later positions can change. If your application must track a particular task across edits, give that task a stable identifier rather than treating index 2 as its permanent address.

Use a tuple to express a fixed grouping

session = ("Python", 25, "Library")
subject, minutes, location = session
print(subject, minutes, location)

This tuple groups a subject, a duration, and a place. Unpacking gives each field a useful name. Python will not let you replace session[1] with another value. If the schedule changes, create a new tuple and assign the name to it.

Tuple immutability concerns the tuple's slots. It does not automatically freeze every object stored inside it. That distinction matters when a tuple contains a list:

record = ("Monday", ["Python"])
record[1].append("Statistics")
print(record)  # ('Monday', ['Python', 'Statistics'])

The tuple still contains the same list object, but the list's contents changed. A tuple is therefore not a general security boundary or a complete guarantee against changes to nested data. The tuple documentation specifies the container behavior.

Choose according to the next operation

Container choices for concrete tasks
SituationStarting choiceReason
A queue of tasks being editedListItems need adding, removing, or rearranging
One fixed coordinate pairTupleThe positions belong to one grouped value
A result with many named fieldsNamed record or dictionaryNames communicate meaning better than positions
A collection that must be deeply protected from changesDesign the full data structureA tuple alone does not freeze nested objects

The table gives starting choices, not rigid laws. A tuple can hold several values of the same type; a list can contain mixed types. A readable design depends on meaning and usage, not a rule that every list must be homogeneous.

Assignment is not copying

original = ["Python", "Statistics"]
alias = original
alias.append("SQL")
print(original)  # ['Python', 'Statistics', 'SQL']
Create one listBind originalBind alias to that listChange through either name
Original teaching diagram: two names can refer to one mutable list.

The assignment creates another reference to the same list. It does not create another list. This is why modifying alias changes what you see through original. The copy documentation explicitly distinguishes assignment from copying.

Use copied = original.copy() when you need a separate outer list. Appending to copied will then leave the outer original list alone. But this is a shallow copy: nested objects remain shared.

original = [["Python"], ["Statistics"]]
copied = original.copy()
copied[0].append("SQL")
print(original[0])  # ['Python', 'SQL']

Before reaching for a deep copy, decide what independence your application actually needs. A planner may work best with immutable task records and a separately editable list of those records. Copying every nested object can be unnecessary, and some objects represent resources that should not be duplicated casually.

Check the small syntax traps

A one-item tuple needs a trailing comma: (25,). The expression (25) is just the integer 25 inside grouping parentheses. Empty containers are [] and (). In either container, index zero is the first item, and index minus one is the last item.

Slices select a range with an excluded end position. For example, tasks[0:2] returns the first two items. A list slice creates a new outer list, but its items still refer to the original objects. Keep that same shallow-copy distinction in mind.

Practice: predict before executing

  1. Which container fits a growing list of collected temperatures?
  2. What does len((25,)) return?
  3. Why did changing copied[0] in the nested example affect the original?
Check your answers

A list fits temperatures you intend to append. The one-item tuple has length 1. The nested example shares its inner list because copying only created a separate outer list; it did not independently copy the inner lists.

When debugging a surprising change, draw the objects and the names pointing to them. That picture is often more useful than asking whether a container is simply mutable or immutable.

Sources and further reading

Source links checked October 13, 2026. Worked examples are original teaching examples; they are not research findings or product benchmarks.

Check your understanding

Which container fits values you plan to append to?

Choose one answer