Ref Set Intersection
# Python3.x Python Set intersection() Method
[ Python Sets](#)
* * *
## Description
The intersection() method is used to return elements that are present in two or more sets, i.e., the intersection.
## Syntax
The syntax for the intersection() method:
set.intersection(set1, set2 ... etc)
## Parameters
* set1 -- Required, the set to find common elements with.
* set2 -- Optional, other sets to find common elements with. Multiple sets can be provided, separated by commas (,).
## Return Value
Returns a new set.
## Example
Return a new set containing elements that are present in both set x and set y:
## Example 1
x = {"apple", "banana", "cherry"} y = {"google", "", "apple"} z = x.intersection(y)print(z)
The output is:
{'apple'}
Calculate the intersection of multiple sets:
## Example 1
x = {"a", "b", "c"} y = {"c", "d", "e"} z = {"f", "g", "c"} result = x.intersection(y, z)print(result)
The output is:
{'c'}
[ Python Sets](#)
YouTip