All lessons
πŸ”’

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))  # 2

Unpacking

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).