Python Sequences: Tuples, Lists, and Strings Explained
Whilst learning Python, I’ve found one foundational concept that pops up everywhere — sequences. Whether you’re building a data pipeline, training a machine learning model, or just automating a task, sequences are essential to how you store and work with data. Today I have been learning about tuples, lists, and strings — unpacking what makes each unique, when to use them, and how they show up in real-world coding scenarios.
What Are Python Sequences?
In Python, a sequence is an ordered collection of items. That means each item has a position (called an index), and you can access them in a predictable order — first item, second item, and so on.
The most commonly used sequences in Python are:
- Tuples
- Lists
- Strings
Let’s break them down…
Tuples: The Immutable Building Blocks
t = (1, 2, 3, 4, 5)A tuple is a lightweight, immutable sequence used to store multiple items in a single variable. Think of tuples as read-only containers. Once you define it, you can’t change it — no adding, removing, or reordering elements.
When to Use Tuples
- When your data shouldn’t change (e.g., coordinates, configuration values).
- When you want faster performance than lists (tuples are slightly faster).
- As keys in a dictionary (because they are hashable).
Lists: The Go-To Data Container
l = [10, 11, 12, 13.5]A list is a dynamic, ordered sequence that is mutable — meaning you can change it by adding, removing, or modifying items.
Get Jenny Core-Holt’s stories in your inbox
Join Medium for free to get updates from this writer.
Lists are the most flexible sequence type in Python, and they are commonly used when working with datasets or collections of information that evolve over time.
When to Use Lists
- When your data will change (e.g. user inputs, dynamic collections).
- When order matters.
- When you want to leverage powerful list methods like
.append(),.pop(), and slicing.
Strings: Sequences of Characters
s = 'string'A string is a sequence too! But instead of numbers or mixed data types, it’s a sequence of characters. Strings are immutable like tuples, but designed specifically to handle textual data.
You can loop through strings just like lists or tuples:
for char in s:
print(char)Iteration and the Power of Sequences
One of the best features of sequences is how naturally they integrate with loops. Consider this loop over a tuple:
for i in t:
print(i, end=' ')Here, t is an iterable, meaning it can be looped through. Any sequence in Python is an iterable by default.
The variable i is your loop variable—each time through the loop, it takes the value of the next item in the sequence.
Nested Loops: Tables in Code
When dealing with more complex data, like 2D tables or matrices, nested loops come into play:
for row in range(3):
for col in range(4):
print(f'({row}, {col})', end=' ')
print()This produces a grid-like output — think of it as printing the rows and columns of a spreadsheet.
A Note on Triple Nested Loops
Python developers usually frown upon triple-nested loops. Why? Because they’re often inefficient and can lead to spaghetti code. Instead, we aim for “Pythonic” solutions — like using comprehensions or itertools (*— Functions creating iterators for efficient looping) to flatten or manage complexity.
Final Thoughts
Python sequences are more than just containers — they’re the backbone of readable, efficient, and elegant code. Understanding the nuances of tuples, lists, and strings will help you write cleaner logic, avoid bugs, and build better programs.









