Skip to main content

What are tuples?

Tuples are like lists, but they can’t be changed once created. They’re immutable (unchangeable) sequences. Use tuples for data that shouldn’t change:
  • Coordinates (x, y)
  • RGB colors (255, 0, 0)
  • Database records
  • Function return values

Creating tuples

A single-item tuple needs a comma: (42,) not (42). Without the comma, Python thinks it’s just parentheses around a number!

Accessing items

Just like lists, tuples use indexing:

Tuple unpacking

Python’s coolest tuple feature:

Common mistakes

What’s next?

Finally, let’s explore sets - collections of unique items!

Sets

Unique collections