capypad
0 day streak
python / beginner
Snippet

Unique Items with Sets

Sets are collections of unique elements; they automatically remove any duplicate values provided during initialization.

snippet.py
python
1
2
numbers = {1, 2, 2, 3}
print(numbers)
Breakdown
1
numbers = {1, 2, 2, 3}
Defines a set containing several numbers, including a duplicate '2'.
2
print(numbers)
Outputs the set, which will only contain {1, 2, 3}.