what is difference between union and update method in set.
Jan 27, 2021
1.update method()
The update()
method updates the current set, by adding items from another set.
example:
set1 = {“apple”, “mango”, “orange”}
set2 = {“one”, ”two”, ”mango”}
set1.update(set2)
print(set1)
output:-{‘two’, ‘one’, ‘orange’, ‘mango’, ‘apple’}
2.union method()
union method return a set as a new set all elements that are in both set.
example:
set1 = {“a”, “b” , “c”}
set2 = {1, 2, 3}
set3 = set1.union(set2)
print(set3)
output:-{1, 2, 3, ‘c’, ‘b’, ‘a’}