In Python, you can find the intersection of two sets using the intersection method or the bitwise AND operator.
In this example,
set1
and set2
, using Python's set notation.intersection
method to find the common elements between set1
and set2
.intersection
.intersection
to display the intersection of the two sets.set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}
intersection = set1.intersection(set2)
print('Intersection of set1 and set2:')
print(intersection)
Intersection of set1 and set2: {3, 4}
In this example,
set1
and set2
, using Python's set notation.&
) to find the common elements between set1
and set2
.intersection
.intersection
to display the intersection of the two sets.set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}
intersection = set1 & set2
print('Intersection of set1 and set2:')
print(intersection)
Intersection of set1 and set2: {3, 4}
In this tutorial, we learned How to find Intersection of Two Sets in Python language with well detailed examples.