Create a set in Python:
animals = {'monkey', 'bear', 'dog', 'monkey', 'cat', 'bear', 'gorilla'}
animals # returns {'monkey', 'bear', 'gorilla', 'dog', 'cat'}
Check if a value is present in a set:
'monkey' in animals # returns True
'shark' in animals # returns False
Create an empty set in Python:
fish = set()
Add items to a set:
fish.add('shark')
fish.add('guppy')
fish.add('whale')
Remove items from a set:
fish.remove('whale')
Use union to combine two sets into a single, deduplicated set:
fish.union(animals) # returns {'guppy', 'monkey', 'bear', 'shark', 'gorilla', 'dog', 'cat'}