A tuple in Python is an ordered, immutable collection of values. It is similar to a list, but once a tuple is created, its items cannot be changed.
Tuples are useful when you want to group related values together and protect the sequence from accidental modification. Python's official docs describe tuples as immutable sequences commonly used for heterogeneous data, while lists are usually used for homogeneous collections you expect to change.
Tested on: Python 3.13.3; kernel 6.14.0-37-generic.
Python tuple quick reference
| Task | Example / method |
|---|---|
| Create a tuple | values = ("red", "green", "blue") |
| Create tuple without parentheses | values = "red", "green", "blue" |
| Create empty tuple | values = () |
| Create one-item tuple | value = ("red",) |
| Convert list to tuple | tuple(my_list) |
| Access item by index | values[0] |
| Access last item | values[-1] |
| Slice a tuple | values[1:3] |
| Unpack tuple values | a, b, c = values |
| Check item exists | "red" in values |
| Count item occurrences | values.count("red") |
| Find item index | values.index("red") |
| Join tuples | tuple1 + tuple2 |
| Repeat tuple | values * 2 |
| Get tuple length | len(values) |
What is a tuple in Python?
A tuple is:
- An ordered collection—you can rely on item position.
- Able to store multiple values in one variable.
- Able to hold mixed data types (strings, numbers, lists, and more).
- Allowed to contain duplicate values.
- Immutable—items cannot be changed after the tuple is created.
person = ("Alice", 25, "HR")
print(person)
print(len(person))
print("Alice" in person)The tuple prints as ('Alice', 25, 'HR'), len returns 3, and membership checks work like other sequences.
Python tuple syntax
Parentheses are commonly used, but commas create the tuple, not the parentheses alone. The official docs note that trailing commas are required for single-item tuples.
Tuple of strings
cars = ("maruti", "jazz", "ecosport")
print(cars)
print(type(cars))Tuple without parentheses
cars = "maruti", "jazz", "ecosport"
print(cars)
print(type(cars))Both forms produce a tuple. Parentheses mainly improve readability.
Tuple of numbers
scores = (90, 85, 88)
print(scores)Mixed data types
record = ("Laptop", 999.99, 5)
print(record)Nested tuple
grid = ((1, 2), (3, 4))
print(grid[0])
print(grid[1][1])The first inner tuple is (1, 2); grid[1][1] is 4.
Create an empty tuple and a single-item tuple
An empty tuple uses ():
empty = ()
print(empty)
print(type(empty))A single-item tuple must include a trailing comma:
print(type(("apple")))
print(type(("apple",)))
one = ("apple",)
print(one)("apple") is a string, not a tuple. ("apple",) is a one-item tuple. This is one of the most common beginner mistakes with tuples.
You can also build a tuple with the tuple() constructor:
numbers = tuple([1, 2, 3])
print(numbers)Access tuple items using indexing
Tuple indexes start at 0. Use positive indexes from the start and negative indexes from the end.
cars = ("maruti", "jazz", "ecosport")
print(cars[0])
print(cars[1])
print(cars[-1])
print(cars[-2])The output is maruti, jazz, ecosport, then jazz for the second-from-last item.
Accessing an invalid index raises IndexError:
cars = ("maruti", "jazz", "ecosport")
try:
print(cars[4])
except IndexError as e:
print(e)Python prints tuple index out of range.
Slice a tuple in Python
Use tuple[start:stop] where start is included and stop is excluded.
numbers = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
print(numbers[1:5])
print(numbers[:4])
print(numbers[6:])
print(numbers[::2])
print(numbers[::-1])You get (1, 2, 3, 4), (0, 1, 2, 3), (6, 7, 8, 9), every second item (0, 2, 4, 6, 8), and the reversed tuple (9, 8, 7, 6, 5, 4, 3, 2, 1, 0).
Tuple is immutable: what does it mean?
You cannot assign a new value to an existing tuple index:
cars = ("maruti", "jazz", "ecosport")
try:
cars[1] = "kwid"
except TypeError as e:
print(e)Python raises 'tuple' object does not support item assignment.
If you need to change many items often, use a list instead. For hashable keys in mappings, see Python dictionary.
Nested objects: if a tuple contains a mutable object such as a list, the tuple itself is still immutable, but the list inside can change:
data = (1, [2, 3])
data[1].append(4)
print(data)The tuple still holds two items, but the list becomes [2, 3, 4].
Can you add, update, or remove tuple items?
You cannot directly add, update, or remove items from an existing tuple. There is no append(), remove(), or item assignment.
You can create a new tuple from old values:
cars = ("maruti", "jazz", "ecosport")
cars = cars[:1] + ("kwid",) + cars[2:]
print(cars)Or convert to a list, modify, and convert back—this creates a new tuple; it does not change the original object in place:
cars = ("maruti", "jazz", "ecosport")
cars_list = list(cars)
cars_list[1] = "kwid"
cars = tuple(cars_list)
print(cars)Both approaches produce ('maruti', 'kwid', 'ecosport').
Tuple methods: count() and index()
Tuples have only two built-in methods because they are immutable:
| Method | Meaning |
|---|---|
count(value) |
Returns how many times a value appears |
index(value) |
Returns the first index of a value |
colors = ("red", "green", "blue", "red")
print(colors.count("red"))
print(colors.index("green"))The output is 2 and 1.
Lists expose many more methods (append, sort, and so on) because they are meant to be changed.
Loop through a tuple
Use a for loop to read each item:
colors = ("red", "green", "blue")
for color in colors:
print(color)Use enumerate() when you also need the index:
for index, color in enumerate(colors):
print(index, color)This prints each color on its own line, then index-and-color pairs starting at 0 red.
Tuple unpacking in Python
Assign tuple values to multiple variables in one step:
person = ("Alice", 25, "HR")
name, age, department = person
print(name)
print(age)
print(department)The number of variables must match the number of tuple items.
Use starred unpacking when you want to collect extra values:
values = (1, 2, 3, 4, 5)
first, *middle, last = values
print(first)
print(middle)
print(last)You get 1, [2, 3, 4], and 5.
Tuple packing and unpacking
Packing groups values into a tuple without extra syntax:
point = 10, 20
print(point)
print(type(point))Unpacking assigns those values back to variables—this is also how multiple assignment works:
a, b = 10, 20
print(a, b)
x, y = y, x
print(x, y)The swap example exchanges values using tuple packing and unpacking on one line.
Tuple vs list in Python
| Feature | Tuple | List |
|---|---|---|
| Syntax | () |
[] |
| Mutable | No | Yes |
| Ordered | Yes | Yes |
| Allows duplicates | Yes | Yes |
| Can store mixed types | Yes | Yes |
| Common use | Fixed related values | Changeable collection |
| Methods | Fewer (count, index) |
More (append, sort, …) |
Use a tuple when the values should stay fixed. Use a list when you need to add, remove, or update items. See list vs set vs tuple vs dictionary for a broader comparison.
To check whether a value is a tuple at runtime, use isinstance(x, tuple) from the type checking guide.
When should you use a tuple?
Good fits for tuples:
- Fixed related values, such as coordinates
(10, 20). - Returning multiple values from a function.
- Dictionary keys when every item inside is hashable (lists cannot be keys; tuples can if their contents are hashable).
- Records that should not change, such as a person row read from a database.
- Clear unpacking at call sites (
name, age = get_user()).
Use a list when the collection will grow, shrink, or be sorted in place.
Common tuple examples
Coordinates:
point = (10, 20)
x, y = point
print(x, y)RGB color:
red = (255, 0, 0)
print(red)Database-like record:
employee = ("Alice", 25, "HR")
name, age, dept = employee
print(f"{name} works in {dept}")Function return values:
def min_max(values):
return min(values), max(values)
smallest, largest = min_max((90, 41, 12, 23))
print(smallest, largest)Join and repeat:
part1 = (1, 2, 3)
part2 = (4, 5)
combined = part1 + part2
repeated = part1 * 2
print(combined)
print(repeated)
print(len(combined))Tuple of tuples:
pairs = ((1, 2), (3, 4))
print(pairs[0])
print(pairs[1][1])These snippets print coordinates, color values, employee info, 12 90, combined/repeated tuples, length 5, and nested access 4.
Mistakes to avoid with tuples
- Forgetting the comma in a single-item tuple —
("apple")is a string;("apple",)is a tuple. - Trying to update a tuple item directly — assignment to
tuple[i]raisesTypeError. - Thinking parentheses alone create a tuple — commas matter;
a = 1, 2already builds a tuple. - Confusing tuple immutability with nested objects — a tuple cannot be reassigned, but a list inside it can still be modified.
- Using a tuple when a list is better — choose a list if you need
append,sort, or frequent in-place edits. - Expecting list-style methods — no
append(),remove(), orsort()on tuples. - Building huge tuples with repeated
+— concatenating many times creates new tuples each time; a list may be more efficient if you are assembling a large sequence.
Summary
A tuple is an ordered, immutable collection in Python. You create tuples with comma-separated values, often written in parentheses. Use indexing, slicing, loops, and unpacking to work with tuple data. For basic inspection, use count() and index(). Choose tuples for fixed data and lists for changeable collections.
Useful references

