Sets in Python is similar to Sets in maths,

Sets Methods

  • set.add(element) # Adds an element in the set.
  • set.remove(element) # Removes an element from the set.
  • set.clear() # Clears the set.
  • set.pop() # Removes a random value.
  • set.union(set2) # Combines the elements of the two sets.
  • set.intersection(set2) # Outputs the common elements in the two sets.

Example

To get {9.0, '9'} as an output in Python, I can :-

dict = {9.0 '9'}
print(dict)

or

dict = {9.0}
dict.add('9')
print(dict)

if we just did dict = {9.0, 9} only 9 will be printed as 9 and 9.0 is same in Python.