Tuples and Immutability
Understand tuples, their immutability, and when to prefer them over lists.
Tuples and Immutability is a free Python Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Introduction
Creating Tuples
t = (1, 2, 3)
singleton = (42,)
print(t, singleton)Tuple Immutability
t = (1, 2, 3)
# t[0] = 99 # TypeError
print(t[0])Tuple Indexing and Slicing
t = (10, 20, 30)
print(t[1])
print(t[:2])Tuple Packing and Unpacking
a, b = 1, 2
a, b = b, a
print(a, b)Tuples as Dictionary Keys
coords = {(0, 0): 'origin', (1, 0): 'right'}
print(coords[(0, 0)])Tuple vs List — When to Use
point = (3.0, 4.0) # tuple: fixed structure
scores = [85, 90, 78] # list: variableNamed Tuples
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
p = Point(3, 4)
print(p.x, p.y)Tuple Methods
t = (1, 2, 2, 3)
print(t.count(2))
print(t.index(2))Tuple Performance
import sys
print(sys.getsizeof((1,2,3)))
print(sys.getsizeof([1,2,3]))Converting Between List and Tuple
t = (1, 2, 3)
lst = list(t)
lst.append(4)
t2 = tuple(lst)
print(t2)Quick Check
Recap
Keep Going
Frequently asked questions
Is the “Tuples and Immutability” lesson free?
Yes — the full text of “Tuples and Immutability” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Tuples and Immutability”?
Understand tuples, their immutability, and when to prefer them over lists. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Tuples and Immutability” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Creating and Accessing Lists
- Modifying Lists
- Tuples and Immutability
- Nested Lists and Iteration