A tuple behaves like a list — ordered, indexable, allows duplicates — but once created it can't be modified: no append, no item assignment. That immutability is exactly why tuples, unlike lists, can be used as dictionary keys or set members, as long as every element inside them is itself hashable. tuple(iterable) eagerly consumes the iterable and copies its elements into the new, fixed sequence.
1Understanding tuple()
A tuple behaves like a list — ordered, indexable, allows duplicates — but once created it can't be modified: no append, no item assignment. That immutability is exactly why tuples, unlike lists, can be used as dictionary keys or set members, as long as every element inside them is itself hashable. tuple(iterable) eagerly consumes the iterable and copies its elements into the new, fixed sequence.
A single-element tuple needs a trailing comma — parentheses around one value alone is just that value, while adding a comma makes it a one-item tuple.
coordinates = tuple([3, 4])
print(coordinates)
single = (5,)
print(single, type(single))2Practical Example
Here is a real-world application of tuple() showing how it is used in production Python code.
distances = {}
distances[(0, 0)] = 0
distances[(1, 1)] = 1.41
print(distances[(1, 1)])3Best Practices
Follow these guidelines when working with tuple():
1. Use a tuple instead of a list for fixed collections that shouldn't change, like coordinates or RGB values, to signal that intent
2. Use tuples as dictionary keys when you need a composite key made of multiple values
3. Prefer named tuples (collections.namedtuple) over plain tuples when the fields need readable names
Tip: A single-element tuple needs a trailing comma — parentheses around one value alone is just that value, while adding a comma makes it a one-item tuple.
coordinates = tuple([3, 4])
print(coordinates)
single = (5,)
print(single, type(single))