Python Tuple

Learn what a tuple is in Python with simple examples. See how to create tuples, access items, use indexing and slicing, unpack tuples, compare tuples with lists, and use tuple methods.

Published

Updated

Read time 8 min read

Reviewed byDeepak Prasad

Python Tuple

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.
python
person = ("Alice", 25, "HR")
print(person)
print(len(person))
print("Alice" in person)
Output

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

python
cars = ("maruti", "jazz", "ecosport")
print(cars)
print(type(cars))
Output

Tuple without parentheses

python
cars = "maruti", "jazz", "ecosport"
print(cars)
print(type(cars))
Output

Both forms produce a tuple. Parentheses mainly improve readability.

Tuple of numbers

python
scores = (90, 85, 88)
print(scores)
Output

Mixed data types

python
record = ("Laptop", 999.99, 5)
print(record)
Output

Nested tuple

python
grid = ((1, 2), (3, 4))
print(grid[0])
print(grid[1][1])
Output

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 ():

python
empty = ()
print(empty)
print(type(empty))
Output

A single-item tuple must include a trailing comma:

python
print(type(("apple")))
print(type(("apple",)))

one = ("apple",)
print(one)
Output

("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:

python
numbers = tuple([1, 2, 3])
print(numbers)
Output

Access tuple items using indexing

Tuple indexes start at 0. Use positive indexes from the start and negative indexes from the end.

python
cars = ("maruti", "jazz", "ecosport")

print(cars[0])
print(cars[1])
print(cars[-1])
print(cars[-2])
Output

The output is maruti, jazz, ecosport, then jazz for the second-from-last item.

Accessing an invalid index raises IndexError:

python
cars = ("maruti", "jazz", "ecosport")

try:
    print(cars[4])
except IndexError as e:
    print(e)
Output

Python prints tuple index out of range.


Slice a tuple in Python

Use tuple[start:stop] where start is included and stop is excluded.

python
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])
Output

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:

python
cars = ("maruti", "jazz", "ecosport")

try:
    cars[1] = "kwid"
except TypeError as e:
    print(e)
Output

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:

python
data = (1, [2, 3])
data[1].append(4)
print(data)
Output

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:

python
cars = ("maruti", "jazz", "ecosport")
cars = cars[:1] + ("kwid",) + cars[2:]
print(cars)
Output

Or convert to a list, modify, and convert back—this creates a new tuple; it does not change the original object in place:

python
cars = ("maruti", "jazz", "ecosport")
cars_list = list(cars)
cars_list[1] = "kwid"
cars = tuple(cars_list)
print(cars)
Output

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
python
colors = ("red", "green", "blue", "red")

print(colors.count("red"))
print(colors.index("green"))
Output

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:

python
colors = ("red", "green", "blue")

for color in colors:
    print(color)
Output

Use enumerate() when you also need the index:

python
for index, color in enumerate(colors):
    print(index, color)
Output

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:

python
person = ("Alice", 25, "HR")
name, age, department = person

print(name)
print(age)
print(department)
Output

The number of variables must match the number of tuple items.

Use starred unpacking when you want to collect extra values:

python
values = (1, 2, 3, 4, 5)
first, *middle, last = values

print(first)
print(middle)
print(last)
Output

You get 1, [2, 3, 4], and 5.


Tuple packing and unpacking

Packing groups values into a tuple without extra syntax:

python
point = 10, 20
print(point)
print(type(point))
Output

Unpacking assigns those values back to variables—this is also how multiple assignment works:

python
a, b = 10, 20
print(a, b)

x, y = y, x
print(x, y)
Output

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:

python
point = (10, 20)
x, y = point
print(x, y)
Output

RGB color:

python
red = (255, 0, 0)
print(red)
Output

Database-like record:

python
employee = ("Alice", 25, "HR")
name, age, dept = employee
print(f"{name} works in {dept}")
Output

Function return values:

python
def min_max(values):
    return min(values), max(values)

smallest, largest = min_max((90, 41, 12, 23))
print(smallest, largest)
Output

Join and repeat:

python
part1 = (1, 2, 3)
part2 = (4, 5)
combined = part1 + part2
repeated = part1 * 2
print(combined)
print(repeated)
print(len(combined))
Output

Tuple of tuples:

python
pairs = ((1, 2), (3, 4))
print(pairs[0])
print(pairs[1][1])
Output

These snippets print coordinates, color values, employee info, 12 90, combined/repeated tuples, length 5, and nested access 4.


Mistakes to avoid with tuples

  1. Forgetting the comma in a single-item tuple("apple") is a string; ("apple",) is a tuple.
  2. Trying to update a tuple item directly — assignment to tuple[i] raises TypeError.
  3. Thinking parentheses alone create a tuple — commas matter; a = 1, 2 already builds a tuple.
  4. Confusing tuple immutability with nested objects — a tuple cannot be reassigned, but a list inside it can still be modified.
  5. Using a tuple when a list is better — choose a list if you need append, sort, or frequent in-place edits.
  6. Expecting list-style methods — no append(), remove(), or sort() on tuples.
  7. 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


Frequently Asked Questions

1. What is a tuple in Python?

A tuple is an ordered, immutable collection of values. You create it with comma-separated items, often written in parentheses. Once created, tuple items cannot be changed.

2. How do you create a single-item tuple in Python?

Add a trailing comma: value = ("apple",). Without the comma, ("apple") is just a string in parentheses, not a tuple.

3. Can you change a tuple in Python?

No. You cannot assign to a tuple index or use list methods like append(). You can build a new tuple from old values, or convert to a list, modify, and convert back—which creates a new tuple rather than changing the original.

4. What is the difference between a tuple and a list in Python?

Both are ordered and allow duplicates. Lists use square brackets and are mutable; tuples use parentheses (optional) and are immutable. Use tuples for fixed related values and lists when you need to add, remove, or update items.

5. What is tuple unpacking in Python?

Unpacking assigns each item in a tuple to separate variables, for example name, age = person. The number of variables must match the tuple length unless you use starred unpacking like first, *rest = values.

6. What methods do tuples have in Python?

Tuples expose count(value) to count occurrences and index(value) to find the first index. They have fewer methods than lists because tuples are immutable.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …