π
Python Tuples
Ordered, unchangeable collections
Reward
+40 XP
What is a tuple?
Tuples are like lists, but immutable β once created, you cannot change them. Use parentheses.
coords = (10, 20)
print(coords[0]) # 10
print(len(coords)) # 2Unpacking
You can unpack tuple values into variables.
point = (3, 7)
x, y = point
print(f"x={x}, y={y}")Try it yourself
Run the example below. Edit it and see what changes.
main.py
Output
Press Run to execute (Ctrl/Cmd+Enter)
Common mistakes
- β Trying to modify a tuple β tuples are immutable.
- β Single-item tuple needs a trailing comma: (1,) not (1).
