Repaso
EspaƱol
PythonCorePY-45

What is the main difference between a list [1, 2] and a tuple (1, 2)?

Options

  1. Lists can hold only numbers; tuples can hold any type
  2. Lists can change after creation; tuples cannot be changed (Correct option)
  3. Tuples cannot be indexed; lists can be indexed by position
  4. There is no real difference; they are two names for one type

Answer

Lists are mutable (can change); tuples are immutable (cannot change after creation)

Why

Both are ordered collections and you can read items by position (x[0]).

A list can change after creation: append, remove or replace items. A tuple is fixed once created.

Use tuples for fixed groups of values, like coordinates (x, y). Because they cannot change, tuples can also be dictionary keys.

Remember

List = changeable. Tuple = fixed.

Key terms

Practice this question in Repaso