Himanshu SharmaSoftware engineer
Let’s talk

Python Tutorial · Lesson 27 of 70

Python tuples: fixed collections of values

Learn what Python tuples are, how to create and unpack them, why a single-item tuple needs a comma, and when to choose a tuple instead of a list.

12 minCollectionsUpdated 14 November 2026

Awaiting technical review. This lesson is readable but not yet listed in search engines.

By the end of this lessonCreate tuples, read and unpack their values, and decide when a tuple is a better choice than a list.

After this lesson you can create tuples, take them apart into separate variables, and choose between a tuple and a list. If you understand lists, you already know most of what a tuple can do.

What a tuple is

A tuple is an ordered collection, just like a list. The difference is that once it is created it cannot change: you cannot add, remove or replace items. We say a tuple is immutable. A tuple is usually written with parentheses:

python
point = (3, 7)
shop = ("Corner Books", "Delhi", 2012)
empty = ()
print(point)
print(shop)
print(empty)
print(type(point))
result
(3, 7)
('Corner Books', 'Delhi', 2012)
()
<class 'tuple'>

You read tuple items the same way as list items, by index and by slice, and you can use len, in and for too:

python
print(shop[0])
print(shop[-1])
print(shop[1:])
print(len(shop))
print("Delhi" in shop)
for part in point:
    print(part)
result
Corner Books
2012
('Delhi', 2012)
3
True
3
7

The parentheses are mostly for readability. It is the commas that build a tuple, so 1, 2, 3 is already a tuple:

python
colours = "red", "green", "blue"
print(colours)
print(type(colours))
result
('red', 'green', 'blue')
<class 'tuple'>

The one-item tuple

Because parentheses also group expressions, (5) is just the number 5. To make a tuple with a single item you need a trailing comma:

python
not_a_tuple = (5)
one = (5,)
print(type(not_a_tuple))
print(type(one))
print(one)
result
<class 'int'>
<class 'tuple'>
(5,)

This looks odd at first, but it is the only way Python can tell the two cases apart.

Tuples cannot be changed

Trying to change a tuple fails:

python
point = (3, 7)
point[0] = 10
result
TypeError: 'tuple' object does not support item assignment

If you need a different tuple, build a new one. You can combine tuples with +:

python
point = (3, 7)
moved = (10,) + point[1:]
print(moved)
print(point)
result
(10, 7)
(3, 7)

Tuples have only two methods, count and index, because nothing else makes sense for a fixed collection:

python
grades = ("A", "B", "A", "C", "A")
print(grades.count("A"))
print(grades.index("C"))
result
3
3

One detail: if a tuple holds a mutable item such as a list, that inner list can still change. The tuple fixes which objects it holds, not what is inside them.

python
box = ("label", [1, 2])
box[1].append(3)
print(box)
result
('label', [1, 2, 3])

Unpacking

The most useful thing about tuples is unpacking: copying each item into its own variable in one line.

python
point = (3, 7)
x, y = point
print(x)
print(y)
name, city, year = shop
print(name, "opened in", year)
result
3
7
Corner Books opened in 2012

The number of names must match the number of items:

python
a, b = (1, 2, 3)
result
ValueError: too many values to unpack (expected 2)

When you only want some of the items, put a star on one name and it collects the leftovers into a list:

python
first, *middle, last = (10, 20, 30, 40, 50)
print(first)
print(middle)
print(last)
result
10
[20, 30, 40]
50

Unpacking also gives the classic way to swap two variables without a temporary one:

python
a = 1
b = 2
a, b = b, a
print(a, b)
result
2 1

A function that wants to return several values does it by returning a tuple, and the caller unpacks it. divmod is a built-in example that returns the quotient and remainder together:

python
quotient, remainder = divmod(17, 5)
print(quotient, remainder)
result
3 2

Converting and choosing

tuple() turns any collection into a tuple, and list() turns a tuple back into a list:

python
print(tuple([1, 2, 3]))
print(list((1, 2, 3)))
print(tuple("abc"))
result
(1, 2, 3)
[1, 2, 3]
('a', 'b', 'c')

So when should you pick one? Use a tuple when the items form a fixed record where each position has a meaning, such as (latitude, longitude) or (name, price). Use a list when you have a number of similar items that may grow, shrink or be sorted. Because tuples cannot change, they are also safe to use as dictionary keys, which you will see later in the course:

python
stock = {("pen", "blue"): 40, ("pen", "red"): 15}
print(stock[("pen", "red")])
result
15

Common mistakes

  • Forgetting the comma in a one-item tuple. ("x") is a string.
  • Trying to change a tuple. If you find yourself wanting to, you probably want a list.
  • Unpacking the wrong number of items. The names on the left must match the length, or use a starred name.
  • Thinking a tuple is deeply frozen. A list inside a tuple can still be changed.
  • Using a tuple when order of growth matters. Building a result item by item is a job for a list.

Exercise

Create a tuple product = ("notebook", 45, 12) holding a name, a price and a stock count. Unpack it into three variables and print a sentence that uses all three. Then create a one-item tuple holding the name only.

Show one possible answer
python
product = ("notebook", 45, 12)
name, price, stock = product
print(name, "costs", price, "and we have", stock)
only_name = (name,)
print(only_name)
result
notebook costs 45 and we have 12
('notebook',)

Previous: List methods. Next: Sets.

Key points

  • A tuple is an ordered collection written with parentheses, like a list, but it cannot be changed after creation.
  • A one-item tuple needs a trailing comma: (5,). Without it the parentheses are just grouping.
  • Unpacking assigns each tuple item to its own name: x, y = point. Star unpacking collects the rest.
  • Use tuples for small fixed records such as coordinates or return values. Use lists for collections that grow or shrink.

Check yourself

1. Which of these is a tuple with exactly one item?
2. What happens when you run point[0] = 5 on point = (1, 2)?
3. After a, b = (10, 20), what is b?
4. Why can a tuple of numbers be used as a dictionary key while a list cannot?