Python tuple() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in type

Definition

In Python, tuple(iterable) creates a tuple, an ordered sequence that is immutable: you cannot add, remove, or replace its items after it is created. tuple([1, 2]) is (1, 2) and tuple() is the empty tuple ().

Because they cannot change, tuples of hashable items are hashable and can be dict keys or set members. They are also what Python uses to return several values from a function and to unpack values on the left of =.

tuple is a built-in type (a class) that you call like a function: each call creates a new tuple object. Like every built-in, it lives in the builtins module and is always available without an import.

Syntax

Pass any iterable, or write a literal with commas.

python
items = tuple(iterable)
point = (3, 4)
single = (5,)          # the comma makes it a tuple
CallWhat it does
tuple([1, 2, 3])Returns (1, 2, 3).
tuple("hi")Returns ('h', 'i').
tuple()Returns ().
(5,)A one-item tuple; (5) is just the int 5.

Tuples have only two methods, count() and index(), because they cannot be modified.

Library declarations
python
tuple(iterable=(), /)
# class tuple: an immutable built-in type

Parameters

ParameterDescription
iterableOptional. Any iterable. Default: empty.

Return Value

Return ValueDescription
tupleA tuple with the iterable's items (an existing tuple may be returned as is).

Python Examples

Example 1 — Create Tuples from Iterables

Convert a list, a string, and a range, and check a one-item tuple.

python
print(tuple([1, 2, 3]))
print(tuple("hi"))
print(tuple(range(3)))
print(tuple())

single = (5,)
print(single, type(single).__name__, len(single))

How It Works

  1. Any iterable. Lists, strings, and ranges all convert to tuples in the same order.
  2. Round brackets. Tuples print in parentheses, and the empty tuple is ().
  3. Comma, not brackets. (5,) is a tuple because of the comma; it prints with the comma too.
  4. Type check. type(single).__name__ is tuple and its length is 1.

Example 2 — Immutability and Tuples as Dict Keys

Try to change a tuple, then use coordinates as dictionary keys.

python
point = tuple([3, 4])

try:
    point[0] = 10
except TypeError:
    print("tuples cannot be changed")

distances = {point: 5.0, (0, 0): 0.0}
print(distances[(3, 4)])
print(tuple([1, 2]) == (1, 2), tuple([1, 2]) == [1, 2])

How It Works

  1. No assignment. point[0] = 10 raises TypeError.
  2. Hashable keys. A tuple of numbers can be a dict key, which lists cannot.
  3. Equal tuples match. Looking up (3, 4) finds the entry stored under point.
  4. Type matters in ==. A tuple equals another tuple with the same items, but never a list.

Example 3 — Return, Unpack, and the Mutable-Item Caveat

Return two values from a function, unpack them, and see that a list inside a tuple can still change.

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


low, high = min_max([7, 2, 9, 4])
print(low, high)

record = tuple(["Ana", [90, 85]])
record[1].append(77)
print(record)
print(record.count("Ana"), record.index([90, 85, 77]))

How It Works

  1. Implicit tuple. return a, b returns one tuple holding both values.
  2. Unpacking. low, high = ... splits the tuple into two names.
  3. Shallow immutability. The tuple still holds the same list, but that list can grow, so 77 appears.
  4. Tuple methods. count() and index() search the items; the list is at index 1.

Frequently Asked Questions

A list is mutable and a tuple is immutable. Tuples are hashable when their items are, so they can be dict keys, and they signal data that should not change.
Add a trailing comma: (5,) or 5,. Without the comma, (5) is just the number 5.
Call tuple(my_list).
No items can be added, removed, or replaced. Build a new tuple instead, for example t + (4,).
It contains a mutable item such as a list or dict. Every item must be hashable for the tuple to be hashable.

Next: type()

Get the class of an object, or create a new class.

type() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful