PYTHON LISTS vs. TUPLES

CBSE Class 11 Computer Science · Interactive Cheat Sheet

MUTABLE LISTS

[ ]
nums = [10, 20, 30] len = 3
  • Ordered & Changeable: Edit items in-place anytime
  • Dynamic & Heterogeneous: Grows freely; mixes types
my_list = [10, "py", 3.5]
empty_list = []
Real-Life: Shopping Cart Playlist To-Do List

7 ESSENTIAL LIST METHODS

In-Place Tools
append(x)Add at end
insert(i, x)Add at index i
extend(seq)Merge items
pop([i])Remove & return
remove(x)Delete first x
sort()Sort ascending
reverse()Flip list order in-place

TUPLE RULES & PACKING

Must-Know CBSE
  • Single-Item Rule: single = (5,) comma needed! (5) is an int
  • Packing & Unpacking: x, y = (4, 9) → x=4, y=9
  • Hashable Dict Keys: loc[(28, 77)] = "Delhi"

IMMUTABLE TUPLES

( )
t = (10, 20, 30)
t[0] = 99 → Locked!
  • Ordered & Unchangeable: Locked after creation (immutable)
  • Fixed Size & Faster: Uses less RAM; quicker iteration
  • Hashable: Safe for dictionary keys & set elements
my_tuple = (10, 20, 30)
single = (5,) # single-item tuple
t[0] → 10 · t[1:3] → (20, 30)
t.count(20) · t.index(30)
Real-Life: GPS Coords Date of Birth RGB Colors
INDEXING & SLICING LAB Works identically on Lists [ ] & Tuples ( )
0
10
-4
1
20
-3
2
30
-2
3
40
-1
Result seq[1:3] → [20, 30]
Feature Lists [ ] Tuples ( )
Mutability Mutable (changeable in-place) Immutable (locked after creation)
Syntax Square brackets [10, 20] Parentheses (10, 20) · single (5,)
Memory More memory (dynamic buffer) Less memory (compact fixed block)
Speed Slightly slower iteration Faster iteration & lookup
Methods Many (append, pop, sort…) Only 2 (count(), index())
Dict Key Support No (unhashable → TypeError) Yes (hashable with immutable items)
Use Case Shopping cart, playlist, to-do list GPS coords, date of birth, RGB colors