tags = {"python", "beginner", "python"}Line-by-line explanation
- Curly braces contain the set values.
- Python appears twice in the code.
- The set stores it only once.
tags.add("coding")Line-by-line explanation
- The add method belongs to the set.
- 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.
Tiny Practice
Create a set that stores red only once.
Starter template
colors = {"red", "red"}
print(colors)Line-by-line explanation
- Two identical values are written.
- A set removes duplicates automatically.
Hint
- Curly braces already create the set.
- Run it without changing the duplicate.
- Observe the output.
Show Solution
colors = {"red", "red"}
print(colors)Line-by-line explanation
- Both written items have the same value.
- The set keeps one red.
- The output contains red once.