Python Tuples Foundation
tuple ( ) Topic 05b Foundation

Tuples — immutable ordered sequences

Foundation lesson for Python tuples. Learn how tuples differ from lists and when to use them for fixed, unchangeable data.

Picture this: a sealed row

A tuple is like a list you cannot change. Good for coordinates and records.

(x, y)packed
→
unpacka, b = t
→
no appendimmutable

Use a list when you need to grow or edit. Use a tuple when the pair should stay fixed.

In easy words: What is a tuple?

A tuple is a box that holds values in order, just like a list. But once you create a tuple, you cannot change it. No adding, no removing, no modifying. It's like a sealed record — perfect for data that should never change.

Diagram — immutable ordered pack

10 20 30 point = (10, 20, 30) — ordered, fixed after creation

Where tuples are used

Tuples are used for GPS coordinates, RGB colors, date-time pairs, database records, dictionary keys, and any situation where you need fixed, unchangeable data.

What is a tuple?

  • Immutable — cannot add, remove, or change items.
  • Indexed from 0 — first item is tuple[0], last is tuple[-1].
  • Parentheses — created with ( ).
  • Fast — tuples are quicker than lists for lookups.

Tuple vs List

  • List: [ ], mutable, use for changeable data.
  • Tuple: ( ), immutable, use for fixed data.
  • Tuples can be dictionary keys; lists cannot.
  • Single-item tuple needs comma: (5,) not (5).

Real world: GPS coordinates

A location is fixed: latitude, longitude = (40.7128, -74.0060) for New York. This should never change during a program. GPS apps use tuples for coordinates because they are sealed — you won't accidentally modify a location.

Click an item — inspect index and value

Immutable Tuple Visualizer

Click a cell to inspect
Why immutability matters

Try to modify (will fail)

Attempting: coordinates[0] = 45 on tuple (40.7128, -74.0060)
TypeError: 'tuple' object does not support item assignment
This protection prevents accidental changes to important data. If you need to modify data, use a list instead.
List vs Tuple comparison
📝 Lists [ ] Mutable (changeable)
append(), pop(), sort()
Good for: shopping carts, playlists
🔒 Tuples ( ) Immutable (sealed)
No modification methods
Good for: coordinates, colors, keys
⚡ Speed Lists: flexible but slower
Tuples: faster for simple data
Tuples are hashable (keys)
📌 Use in Dict tuple_key = (1, 2)
dict[tuple_key] = "value"
Lists cannot be dict keys

Syntax reference

1coords = (40.7128, -74.0060)
2print(coords[0]) # 40.7128 — first item
3print(coords[-1]) # -74.0060 — last item
4color = (255, 0, 0) # RGB red
5print(len(coords)) # 2 items
6empty = () # empty tuple
7single = (5,) # note the comma!

Example Program

1rgb_red = (255, 0, 0)
2rgb_blue = (0, 0, 255)
3print(f"Red: {rgb_red}, Blue: {rgb_blue}")
4colors_used = [rgb_red, rgb_blue]

Tuples — Topic Quiz

Check understanding

Answer all questions, then click Check answers. Use this before Practice in the editor.

Q1. Main difference of a tuple vs a list?

Q2. How do you write a 2D point tuple?

Q3. Unpacking `x, y = (3, 4)` sets y to…

Q4. When prefer a tuple?

Score: —