Set union, intersection, difference operation in Python

Author: Al-mamun Sarkar Date: 2020-03-24 20:35:20

Set union operation using union() function, intersection operations using intersection() function, difference operations using difference() function in python.

A = {1, 2, 3, 4, 5}
B = {6, 7, 8, 1, 4}

print(A.union(B))

print(A.intersection(B))

print(A.difference(B))

Output:

{1, 2, 3, 4, 5, 6, 7, 8}
{1, 4}
{2, 3, 5}