Skip to main content
Practice

Tuples and Sets in Python

As you learn Python, you’ll discover different ways to store and organize data. Two useful types you’ll see often are tuples and sets.

They may sound similar, but they behave very differently — and are used in different situations.


Tuples: Think of a Locked Box

Imagine a tuple like a locked box with a few labeled compartments: once you close it, you can’t change what’s inside.

This is useful when the data should stay constant, like GPS coordinates or a student’s birthdate.

  • They are ordered: the position of each item matters.
  • You can’t change them (immutable).
  • You can still access items using indexing: my_tuple[0]

Sets: Think of a Toy Basket

Now imagine a set like a basket of toys where you don’t care about the order — but you do care that there are no duplicates.

  • Sets remove repeated values automatically.
  • You can add or remove items anytime.
  • The order is unpredictable — sets are unordered.

Why Learn These?

When you’re analyzing data, you’ll run into situations where you need:

  • Tuples to pass fixed groups of values (e.g., coordinates, RGB colors).
  • Sets to clean up repeated entries or compare unique values (e.g., email addresses, tags, categories).

You’ll use both often — especially when writing clean, efficient code.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.