A tuple is an ordered group of values, like a list, but it is immutable: once you create it, its items cannot be added, removed, or replaced. You write it with commas, usually inside parentheses: (3, 4). Each item has a position, called an index, starting at 0.
Use a tuple for values that belong together and should stay fixed, such as a point, a date, or a row of data. A tuple has only two methods, count() and index(), listed on the Tuple Methods index.
Syntax
Python Syntax
Commas create the tuple; square brackets after it read one item by index or several by slice:
Python
point = (3, 4) # parentheses and commas
colors = "red", "green", "blue" # the commas make the tuple
print(point[0], colors[-1]) # 3 blue
print(colors[:2]) # ('red', 'green')
print(len(colors), "green" in colors) # 3 True
x, y = point # unpacking
print(x + y) # 7
The comma makes the tuple, not the parentheses.
(5) is just the number 5; (5,) is a tuple holding 5. The only tuple you write with parentheses alone is the empty one, ().
Concept
How Tuples Behave
Rule
What it means
Ordered
Items keep the position you gave them, and two tuples are equal only when they hold equal items in the same order.
Immutable
After a tuple is created you cannot add, remove, or replace items: t[0] = 1 raises TypeError. "Immutable" simply means "cannot be changed".
Duplicates allowed
(6, 6, 6) is a valid tuple of three items, and count() tells you how often a value repeats.
Mixed types
("Ada", 36, True, None) holds a str, an int, a bool, and None side by side.
Zero-based indexes
The first item is t[0], and reading a position past the end raises IndexError.
Negative indexes
t[-1] is the last item and t[-2] the one before it.
Hashable
A tuple whose items are all hashable (numbers, strings, other such tuples) can be a dict key or a set member. Hashable means Python can turn the value into a fixed number for fast lookups, which only works for values that never change.
Reference
Creating Tuples
Code
What you get
()
Empty tuple; tuple() gives the same.
(7,)
One item: the trailing comma is required.
1, 2, 3
Tuple packing: commas without parentheses.
tuple([1, 2])
From a list, or any other iterable.
tuple("abc")
From a string: one character per item.
tuple(range(3))
From a range: (0, 1, 2).
The tuple() constructor turns any iterable into a tuple, and len() counts its items. Writing values separated by commas without brackets is called tuple packing.
Concept
Immutability: What Can and Cannot Change
Assigning to an item, as in t[0] = 1, raises TypeError, and tuples have no append() or remove(). To get a "changed" tuple, build a new one, such as t + (4,), or convert with list(t), change the list, and turn it back with tuple().
A tuple fixes which objects it holds, not what happens inside them. If one item is a list, that list can still grow: ("box", [1, 2]) becomes ("box", [1, 2, 3]) after an append(3) on the inner list. Such a tuple is also no longer hashable, so it cannot be a dict key.
Reference
Packing and Unpacking
Code
What it does
a, b = t
One name per item; a different number of items raises ValueError.
a, b = b, a
Swap two variables in one line.
first, *rest = t
first gets item 0 and rest a list of the others.
return x, y
A function returns two values packed into one tuple.
for x, y in points:
Unpack each (x, y) pair while looping.
Unpacking also works in loops over zip() and enumerate(), which both produce tuples.
Reference
Tuple Operators
Code
Result
len(t)
Number of items.
x in t
True if some item is equal to x.
t + other
New tuple joining both; other must also be a tuple.
t * n
New tuple with the items repeated n times.
(1, 2) < (1, 3)
True: tuples compare item by item from the left; the first items are equal, so 2 < 3 decides.
t == other
True when both have the same length and equal items in the same order.
Named tuples. When each position has a meaning, collections.namedtuple lets you name the positions, so you can write p.x instead of p[0]. A named tuple is still a tuple: it is immutable and has the same count() and index() methods.
Compare
Tuple vs List
Feature
Tuple
List
Written as
(1, 2, 1) or 1, 2, 1
[1, 2, 1]
Change after creation?
No: immutable
Yes: mutable
Named methods
2: count(), index()
11, such as append(), pop(), sort()
Dict key or set member?
Yes, if every item is hashable
Never
Typical use
Fixed records: a point, an RGB color, a date as (2026, 11, 19), several return values
Collections that grow, shrink, or get sorted
Pick a tuple when the data should not change by accident, and a list when it must change. Read more on the Python List page and the List Methods index.
Reference
Common Mistakes
Mistake
Do this instead
x = (5)
That is the int 5. Write (5,) or 5, for a one-item tuple.
t.append(4)
Raises AttributeError: tuples have no append(). Build a new tuple with t + (4,).
t.sort()
Raises AttributeError too. Use sorted(t), which returns a new list, or tuple(sorted(t)).
a, b = (1, 2, 3)
Raises ValueError: three items do not fit two names. Use a, b, c or a, *rest.
{(1, [2]): "x"}
Raises TypeError: the list inside makes the tuple unhashable, so it cannot be a dict key.
Code
Python Examples
Fixed data only, so the output is the same on every machine.
Example 1 — Create Tuples Five Ways and Spot the Comma Trap
An empty tuple, a one-item tuple, a number that only looks like a tuple, bare commas, and the tuple() constructor on a list and on a string.
Reading works like a list. Index 0 is red (255), index -1 counts back from the end to blue (0), and every slice returns a new tuple.
Writing is refused. Assigning to rgb[0] raises TypeError, because a tuple is immutable; the except block prints our own message.
Fixed slots, changeable contents. The tuple still holds the same list object, but that list is mutable, so append(3) changes what you see inside shelf.
Example 3 — Unpack Results, Swap Values, and Use a Tuple as a Dict Key
Return two values from a function, swap two names, catch "the rest" with a star, look up a dict by a coordinate key, and compare two tuples.
Python
def min_max(values):
return min(values), max(values)
low, high = min_max((7, 3, 9, 4))
print(low, high)
a, b = 1, 2
a, b = b, a
print(a, b)
first, *rest = ("gold", "silver", "bronze")
print(first, rest)
cities = {(40.7, -74.0): "New York"}
print(cities[(40.7, -74.0)], (1, 2) < (1, 3))
Output
3 9
2 1
gold ['silver', 'bronze']
New York True
How It Works
Several return values.return min(values), max(values) packs two results into one tuple, and low, high = ... unpacks it into two names.
A one-line swap. The right side b, a is packed into a tuple first and then unpacked, so the two names trade values with no temporary variable.
Star, keys, and comparison.*rest collects the leftover items in a list, a tuple of numbers is hashable so it works as a dict key, and tuples compare item by item: 2 is less than 3, so the result is True.
A tuple is a built-in, ordered, immutable sequence written with commas and usually parentheses, such as (3, "a", None). You read items by index, starting at 0, but you cannot change them.
Put a comma after the item: (5,) or just 5,. Without the comma, (5) is only the number 5 inside parentheses.
The tuple itself cannot: you cannot add, remove, or replace its items. But if an item is a mutable object such as a list, that list can still change inside the tuple.
Use a tuple for a fixed group of values, such as a point (x, y), an RGB color, or a record used as a dict key. Use a list when items will be added, removed, or sorted in place.
You build a new tuple: t = t + (4,). For many changes, convert with list(t), change the list, and turn it back with tuple().