Python Sets

Python also includes a data type for sets. A set is an unordered collection with no duplicate elements.

  Basic uses include membership testing and eliminating duplicate entries.

  Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.

  Curly braces or the set() function can be used to create sets.

  Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary.

Properties of set

#creating set
print("length of my_set is ",len(my_set))
{1, 2, 3, 4, 5}
length of my_set is  5

  Order of elements are not preserve.

  duplicate elements are not allowed.

woman avatar

What we are going to learn in Data Structure