The inbuilt update()
method in Python is used to update the set that calls the method with items from other iterables, like lists and tuples.
set1.update(iterable)
The update()
method requires only one iterable to be passed as a parameter.
It is important to note that this method only returns None
. Instead of a return value, the set that calls the method is simply updated with another iterable.
#Updating a set with another set.#Since the elements 'Dogs' and 'Seals' were already present#in x, even in the updated set only one instance of these#elements will remain.x = {'Cats', 'Dogs', 'Elephants', 'Seals'}y = {'Dogs', 'Lions', 'Seals', 'Parrots'}x.update(y)print(x)
#Updating x, with a tuple y#x remains a set, even after being updated with a tuplex = {'Cats', 'Dogs', 'Elephants', 'Seals'}y = ('Dogs', 'Lions', 'Seals', 'Parrots')x.update(y)print(x)print(type(x))