Member-only story
Fluent Python Series Chapter 3: Understanding Tuples — Beyond Immutable Lists
This blog is part of my Fluent Python series.
If you don’t have a medium paid subscription, follow this link.
After exploring list comprehensions and generator expressions in our previous chapter, let’s dive into one of Python’s most versatile yet often misunderstood data structures: tuples. While commonly viewed as immutable lists, tuples serve distinct purposes that make them invaluable in Python programming.
Tuples as Records
One of the most powerful applications of tuples is their use as records. When used this way, the tuple’s position, rather than its immutability, becomes its defining characteristic. Each position in the tuple represents a specific field of the record.
# Student records: (name, age, city)
students = [
('Shubham', 23, 'Pune'),
('Priya', 21, 'Mumbai'),
('Raj', 24, 'Delhi'),
('Anita', 22, 'Bangalore')
]
# Unpacking tuples in a for loop
for name, age, city in students:
print(f"{name} is {age} years old and lives in {city}")This code demonstrates tuple unpacking, where each element of the tuple maps to a specific variable. The position of each element carries meaning: first position for name, second for age, and third for city.
Tuples as Immutable Lists
While records are one use case, tuples can indeed serve as immutable lists. This…





