Python - Intro to Sets
Code Life
By Pierre Marsaa
What is a Set?
A set is a collection of unique elements in Python. The most important characteristic of a set is that it automatically removes duplicates - each element can only appear once.
Sets are created using curly braces {} or the set() function:
↗️
Loading editor...
↶
↷
Notice how the set contains unique values. If we try to add duplicates, the set will keep only one copy of each element.
Sets are Unordered
Unlike lists, sets don't maintain any specific order. The elements might appear in a different order each time you print the set.
Verify