EN
Python - add sets
0
points
In this article, we would like to show you how to add two sets together in Python.
Quick solution:
set1.update(set2)
Practical example
In this example, we use update()
method to add my_set2
to my_set1
.
my_set1 = {'A', 'B', 'C'}
my_set2 = {'D', 'E'}
my_set1.update(my_set2)
print(my_set1) # {'B', 'C', 'E', 'D', 'A'}
Output:
{'B', 'C', 'E', 'D', 'A'}