HomeCourseModule 06 › Tuples and when to use them

Tuples and when to use them

Module 06 · Data Structures5 min readBeginner

What you'll learn

  • Create tuples with and without parentheses
  • Unpack tuples
  • Pick tuple vs list correctly

A tuple is an immutable list

point = (10, 20)
rgb = (255, 0, 128)

point[0]      # 10
point[0] = 5  # TypeError — tuples are immutable

The bare-comma shortcut

point = 10, 20   # also a tuple — parens are optional
x, y = point     # unpack into two variables

When to use a tuple

When to use a list

Key takeaways

  • Tuples are immutable. Use them for fixed groupings.
  • Parentheses around tuples are optional in most cases.
  • Tuples can be dict keys; lists cannot.

Day-of-week dict

Use tuples of (year, month, day) as keys in a dict. Add three keys with notes as values. Print one of them.

📹 Video walkthrough
A video walkthrough of this lesson will be embedded here. Until then, the written walkthrough above mirrors what the video will cover step-for-step.