Introduction to Sets
Learn about the usage of sets in Python.
We'll cover the following...
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 itemc = {'Thomas', 25, 34555.50} # set with multiple itemsd = {10, 10, 10, 10} # only one 10 gets storedprint(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 ...