What are Sets in Python?

A Set is an unordered collection data type that is iterateable, mutable and has no duplicate elements. Python’s set class represents the mathematical notion of a set. The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set.

Example:

# Python program to # demonstrate sets 

# Same as {"a", "b", "c"} 
myset = set(["a", "b", "c"])
 print(myset) 

# Adding element to the set 
myset.add("d")
print(myset)

Output:

{'c', 'b', 'a'} {'d', 'c', 'b', 'a'}