EN
Python - print difference of two sets
0 points
In this article, we would like to show you how to print the difference of two sets in Python.
In this example, we use symmetric_difference_update()
to get the difference of my_set1
and my_set2
.
xxxxxxxxxx
1
my_set1 = {'A', 'B', 'C'}
2
my_set2 = {'D', 'B', 'C'}
3
4
my_set1.symmetric_difference_update(my_set2)
5
6
print(my_set1) # {'D', 'A'}
Output:
xxxxxxxxxx
1
{'D', 'A'}