Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →A Python tuple is an ordered, immutable sequence: after creation, you cannot replace or remove its element references. Tuples are formed by commas, accessed with familiar sequence operations, and often used for fixed collections of values or multiple-value assignment. A tuple can serve as a dictionary key only when every value it contains is hashable.
What is a tuple in Python?
The Python 3.12.15 built-in types reference describes tuples as “immutable sequences, typically used to store collections of heterogeneous data.” In practical terms, a tuple keeps values in order and lets you read them, but does not let you change which objects occupy its slots after it has been created. See the Python built-in types reference.
Tuples are useful for fixed records, such as a point with an x- and y-coordinate. Lists are mutable sequences, better suited to collections whose contents need to be added, removed, or replaced.
| Feature | Tuple | List |
|---|---|---|
| Can the sequence’s element references be changed? | No | Yes |
| Common role | Fixed group of values or record | Collection that may change |
| Creation syntax | Comma-separated values, often shown in parentheses | Comma-separated values in square brackets |
| Mutation methods | No methods to add, remove, or replace elements | Methods include append(), remove(), and pop() |
How do you create a tuple?
The comma forms a tuple; parentheses commonly group tuple values, but are not what makes them a tuple. The Python 3.14.8 tutorial puts it simply: “A tuple consists of a number of values separated by commas, for instance:” See Python’s Data Structures tutorial.
#1 Best Overall
empty = ()
single = (42,)
pair = 1, 2
empty is an empty tuple. The comma in (42,) is essential: (42) is just the integer 42 grouped by parentheses. In pair, the comma creates the tuple, and parentheses can be omitted because the assignment syntax permits it. Parentheses are still useful when they make a longer expression easier to read.
You can also create a tuple from an iterable with the built-in tuple(), for example tuple([1, 2]). An empty call, tuple(), makes an empty tuple.
Rank #2
How do you access tuple elements?
Tuples support sequence operations: zero-based indexing, slicing, iteration, membership tests, concatenation, repetition, and len().
point = (4, 7)
first = point[0] # 4
first_two = point[:2] # (4, 7)
contains_four = 4 in point # True
size = len(point) # 2
Index 0 refers to the first element. A slice such as point[:2] returns a new tuple containing the selected elements; it does not alter the original. You can loop over values with for value in point:, combine tuples with +, or repeat one with *.
Recommended Free Tools
The two built-in tuple methods are count(value), which returns the number of occurrences, and index(value), which returns the position of the first matching value. Calling index() when the value is absent raises ValueError.
values = (3, 5, 3)
values.count(3) # 2
values.index(5) # 1
values.index(9) # raises ValueError
How do you unpack a tuple?
Unpacking assigns tuple items to variables in one statement. The number of receiving targets must match the number of values unless you use a starred target.
point = (4, 7)
x, y = point
# x is 4; y is 7
Unpacking is also useful when a function returns multiple values: a function can return a tuple, then its caller can assign the elements to separate variables. The Python tutorial documents tuple packing and sequence unpacking in its data structures guide.
Are tuples mutable?
A tuple is immutable, but that describes its element references—not necessarily the objects referenced by its elements. If a tuple contains a mutable object such as a list, you cannot rebind the tuple slot, but you can modify the list itself.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
items = ("labels", ["draft"])
items[1].append("published") # allowed
# items[1] = [] # TypeError: cannot reassign a tuple item
After the append, the tuple still refers to the same list, whose contents have changed. This is shallow immutability, not deep immutability.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Can tuples be used as dictionary keys?
Yes, if every value inside the tuple is hashable. A tuple of numbers such as (4, 7) can be a dictionary key. A tuple containing a list cannot, because lists are unhashable.
coordinates = {(4, 7): "point"} # valid
invalid_key = (4, [7])
# data = {invalid_key: "point"} # TypeError: unhashable type: 'list'
This rule applies to nested contents too: every contained value must be hashable for the tuple itself to be hashable. Python’s glossary explains hashability and its relationship to dictionary keys.
When should you use a named tuple?
If a tuple represents a record and expressions such as person[0] are unclear, named fields can make code easier to understand. Python’s built-in types reference notes that a named tuple may be more appropriate when access by name is clearer than access by index. The collections.namedtuple() factory creates tuple subclasses with named fields; see the built-in types reference.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




