Python · Stage 5 – Grouping Data · Lesson 32 of 50

Sets and Unique Values

Store unique values when order and duplicates do not matter.

tags = {"python", "beginner", "python"}
Line-by-line explanation
  1. Curly braces contain the set values.
  2. Python appears twice in the code.
  3. The set stores it only once.
tags.add("coding")
Line-by-line explanation
  1. The add method belongs to the set.
  2. Coding is inserted if it is not already present.

Sets are especially useful for fast membership checks and removing duplicates. They do not promise list-style position order.