tuple()

tuple([iterable])
Returns: tuple · Updated March 13, 2026 · Built-in Functions
built-in immutable sequence conversion

The tuple() function creates an immutable, ordered sequence from an iterable. Tuples are similar to lists but cannot be modified after creation, making them useful for fixed collections of items and as dictionary keys.

Syntax

tuple()
tuple(iterable)

Parameters

ParameterTypeDefaultDescription
iterableiterableAny iterable (list, string, dict, set, range, etc.). If omitted, returns an empty tuple.

Examples

Basic usage

# From a list
numbers = tuple([1, 2, 3, 4, 5])
print(numbers)
# (1, 2, 3, 4, 5)

# From a string
letters = tuple("hello")
print(letters)
# ('h', 'e', 'l', 'l', 'o')

# From a range
ranges = tuple(range(5))
print(ranges)
# (0, 1, 2, 3, 4)

Empty tuple

empty = tuple()
print(empty)
# ()

# This is different from tuple literal
empty_list = []
empty_tuple = tuple(empty_list)
print(empty_tuple)
# ()

From a dictionary (only keys)

data = {"a": 1, "b": 2, "c": 3}
keys = tuple(data)
print(keys)
# ('a', 'b', 'c')

Common Patterns

Converting to tuple for immutability

# Lists are mutable - can be changed
my_list = [1, 2, 3]
my_list.append(4)

# Tuples are immutable - safer for fixed data
my_tuple = tuple([1, 2, 3])
# my_tuple.append(4)  # AttributeError!

# Use tuple unpacking
x, y, z = (10, 20, 30)
print(x, y, z)  # 10 20 30

Tuple as dictionary key

# Lists cannot be dict keys (unhashable)
# location = {["nyc"]: "USA"}  # TypeError!

# Tuples can - useful for composite keys
location = {("nyc", "US"): "USA", ("lon", "UK"): "UK"}
print(location[("nyc", "US")])
# USA

Returning multiple values from functions

def divide(a, b):
    quotient = a // b
    remainder = a % b
    return (quotient, remainder)  # Returns a tuple

result = divide(17, 5)
print(result)  # (3, 2)
print(type(result))  # <class 'tuple'>

Tuple vs List

Featuretuplelist
MutableNoYes
Hashable (dict key)YesNo
MemoryLessMore
IterationFasterSlower

See Also