Python Program to Illustrate Different Set Operations: In this example, we have defined two set variables and we have performed different set operations: union, intersection, difference, and symmetric difference.
Python Program to Illustrate Different Set Operations
Source Code
A = {4, 2, 4, 0, 8};
B = {3, 2, 7, 4, 0};
# set union
print("Union of A and B is",A | B)
# set intersection
print("Intersection of A and B is",A & B)
# set difference
print("Difference of A and B is",A - B)
# set symmetric difference
print("Symmetric difference of A and B is",A ^ B)
Output
Python Program to Illustrate Different Set Operations