Tuples are another way of storing collections of items in Python, much like lists. The big difference is that tuples cannot be changed once you’ve created them. That makes them immutable — a fancy way of saying “set in stone”. Tuples are handy when you want to group pieces of information together and make sure they stay the same throughout your programme.
Creating Tuples
Tuples are made using round brackets (). You can put numbers, words, or even a mix of different types inside.
coordinates = (10, 20)
print(coordinates)
# (10, 20)
colours = ("red", "green", "blue")
print(colours)
# ('red', 'green', 'blue')
If you only need a tuple with one item, remember to include a comma, otherwise Python just sees it as a normal value:
single = ("apple",)
print(single)
# ('apple',)
Things to try:
- Create a tuple with three of your favourite animals.
- Make a tuple with one item and print it.
- Try mixing numbers and strings in the same tuple.
Why Tuples Are Useful
Because tuples are immutable, they’re perfect for storing data that shouldn’t change. For example, the x and y coordinates of a location, or the days of the week.
days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
print(days)
# ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')
You can read items from a tuple using their index, just like with lists:
print(days[0])
# Monday
print(days[6])
# Sunday
Things to try:
- Make a tuple of four numbers and print the last one using its index.
- Create a tuple of months in a season (e.g., winter months).
Tuples Are Immutable
The important thing to remember is that you cannot change a tuple once it’s created.
colours = ("red", "green", "blue")
# Trying this:
# colours[0] = "yellow"
# will give an error:
# TypeError: 'tuple' object does not support item assignment
This means you can’t add, remove, or replace items in a tuple directly.
Things to try:
- Try to change an item in a tuple and see what error Python gives you.
- Attempt to append something to a tuple and check the result.
Tuples in Lists
While tuples themselves can’t be changed, you can store them inside a list. This gives you the best of both worlds: the list can be modified, but the individual tuples inside remain fixed.
students = [("Alice", 21), ("Bob", 22), ("Charlie", 20)]
print(students)
# [('Alice', 21), ('Bob', 22), ('Charlie', 20)]
students.append(("Daisy", 23))
print(students)
# [('Alice', 21), ('Bob', 22), ('Charlie', 20), ('Daisy', 23)]
Here, each student’s details are kept safe in a tuple, but you can still add or remove students from the list.
Things to try:
- Create a list of two tuples, each with a fruit and its price. Add a third fruit and price.
- Remove one of the tuples from your list.
Sorting Tuples in Lists
Although you can’t sort a tuple itself, you can sort a list of tuples. Python will look at the first item in each tuple when deciding the order, and if those are the same, it will check the second.
students = [("Alice", 21), ("Bob", 22), ("Charlie", 20)]
students.sort()
print(students)
# [('Alice', 21), ('Bob', 22), ('Charlie', 20)]
This sorts by name because the name comes first in each tuple. You can also sort by age by telling Python to look at the second item:
students.sort(key=lambda x: x[1])
print(students)
# [('Charlie', 20), ('Alice', 21), ('Bob', 22)]
Things to try:
- Create a list of three tuples, each containing a person’s name and age. Sort them alphabetically.
- Sort the same list by age instead of by name.
Wrapping Up
Tuples are like lists that can’t be changed. They’re brilliant for storing fixed data, and when combined with lists, they become very powerful. You’ll often use them when you want information grouped neatly together and kept safe from accidental changes.





