...

/

Introduction to Sets

Introduction to Sets

Learn about the usage of sets in Python.

What are sets?

Sets are collections of data items that do not contain duplicate entries.

Press + to interact
a = set( ) # empty set, use ( ) instead of { }
b = {20} # set with one item
c = {'Thomas', 25, 34555.50} # set with multiple items
d = {10, 10, 10, 10} # only one 10 gets stored
print(a)
print(b)
print(c)
print(d)

While storing an element in a set, its hash value is computed using a hashing technique to determine where it should be stored in the set.

Since the hash value of an element will always be the same, no matter in which order we ...