How to Find the Intersection of Two Sets

set1 = {1, 2, 3, 4, 5}
set2 = {4, 5, 6, 7, 8}
intersection = set1.intersection(set2)
print(f"Set 1: {set1}\nSet 2: {set2}\nIntersection: {intersection}")

Output:

Set 1: {1, 2, 3, 4, 5}
Set 2: {4, 5, 6, 7, 8}
Intersection: {4, 5}

Leave a Comment

Your email address will not be published.