# Python Set intersection example :

*Intersection* is used to find out the common elements between two Sets. Symbol *‘∩’* is used to denote intersection.

For example :

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

In the above example, we have two Set *A* and *B* and we are finding out the intersection between them *A∩B*. The intersection is the common elements between *A* and *B*.

From the above example, it is clear that *A∩B = B∩C*.

## Finding intersection in Python :

Python comes with an inbuilt method *intersection()* to find out the intersection between two or more sets. In this blog post, we will show you how to use *intersection()* to find out the intersection between multiple sets in python. The syntax of the *intersection()* method is as below :

s.intersection(*t)

*It will find the intersection between set s and one or multiple sets. It returns the final set.*

### Example :

Let’s try to implement it with an example :

firstSet = {1,2,3} secondSet = {2,4,5} thirdSet = {1,10,2,4} print("firstSet : ",firstSet) print("secondSet : ",secondSet) print("thirdSet : ",thirdSet) print("firstSet ∩ secondSet : ",firstSet.intersection(secondSet)) print("firstSet ∩ thirdSet : ",firstSet.intersection(thirdSet)) print("firstSet ∩ secondSet ∩ thirdSet : ",firstSet.intersection(secondSet,thirdSet))

It will print the below output :

firstSet : {1, 2, 3} secondSet : {2, 4, 5} thirdSet : {1, 10, 2, 4} firstSet ∩ secondSet : {2} firstSet ∩ thirdSet : {1, 2} firstSet ∩ secondSet ∩ thirdSet : {2}

As you can see, the first two times we have to find out the intersection between two sets but last time we have calculated the intersection between three sets.

### Conclusion :

*intersection()* is really a useful method to find out the intersection between sets in python. Try to implement the example we have shown above and drop one comment below if you have any queries.

You might also like :

- Python Set
- Python 3 program to find union of two lists using set
- Python add and remove elements from a list
- Python program to find out numbers in a list divisible by two numbers
- Python program to find the middle element of a random number list
- Python program to convert a list to string