Returns tuple·Updated May 12, 2026·Built-in Functions
built-inimmutablesequenceconversion
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
Parameter
Type
Default
Description
iterable
iterable
—
Any iterable (list, string, dict, set, range, etc.). If omitted, returns an empty tuple.
Examples
Basic usage
# From a listnumbers = tuple([1, 2, 3, 4, 5])print(numbers)# (1, 2, 3, 4, 5)# From a stringletters = tuple("hello")print(letters)# ('h', 'e', 'l', 'l', 'o')# From a rangeranges = tuple(range(5))print(ranges)# (0, 1, 2, 3, 4)
Empty tuple
empty = tuple()print(empty)# ()# This is different from tuple literalempty_list = []empty_tuple = tuple(empty_list)print(empty_tuple)# ()
# Lists are mutable - can be changedmy_list = [1, 2, 3]my_list.append(4)# Tuples are immutable - safer for fixed datamy_tuple = tuple([1, 2, 3])# my_tuple.append(4) # AttributeError!# Use tuple unpackingx, 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 keyslocation = {("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 tupleresult = divide(17, 5)print(result) # (3, 2)print(type(result)) # <class 'tuple'>