Solve “Word Frequency Counter”

Free. Runs in your browser, no install.

Python · Collections & Basics

List vs tuple

Easylisttuplemutableimmutablecollections

Interview question

What is the difference between a list and a tuple in Python?

How to answer

The short answer

Lists and tuples both hold ordered sequences of values, but you use them for different jobs.

List (list)

  • Mutable: you can append, insert, remove, and reassign elements.
  • Written with square brackets: [1, 2, 3].
  • Typical use: collections that grow or change (rows, buffers, scratch work).

Tuple (tuple)

  • Immutable: once created, you cannot change length or replace elements (though mutable objects *inside* a tuple can still mutate).
  • Written with parentheses: (1, 2, 3) or just commas: 1, 2, 3.
  • Typical use: fixed records, keys (if all elements are hashable), multiple return values, safer APIs.

Why it matters in interviews

Immutability makes tuples hashable (when contents are hashable), so they can be dict keys or set members. Lists cannot. Tuples are also slightly cheaper and communicate "this sequence should not change."

Python
nums = [10, 20, 30]
nums.append(40)          # OK
nums[0] = 99             # OK

point = (10, 20)
# point[0] = 99          # TypeError: 'tuple' object does not support item assignment

# Tuple as a dict key
locations = {(10, 20): "warehouse A"}

# Mutable object inside an immutable tuple
bag = ([1, 2], "label")
bag[0].append(3)         # OK: list inside mutates; tuple structure unchanged
print(bag)               # ([1, 2, 3], 'label')

Interview tip: Say "lists are mutable ordered sequences; tuples are immutable ordered sequences," then mention hashability and intent.

Lock it in with a real drill

You remember an answer longer once you have used it. Try a hands-on problem on this concept.

Open related drill