Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. List vs tuple

Python · Collections & Basics

List vs tuple

Easypython-01
listtuplemutableimmutablecollections

Question

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

Solution

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, dictionary 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."

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.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext