Set union, intersection, difference operation in Python

Set union, intersection, difference operation in Python

Instructor-svgAl-Mamun Sarkar
Mar 24 , 2020

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}

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram