Method signature
intersection(anotherSet_in)
Method overview
- The intersection of two sets is given by this method which selects the elements that are common to both the sets.
Parameters
anotherSet_in - The second set from which common elements are drawn along with the current/this set, to form the intersection set
Example
# Example Python program that creates an intersection of two sets
# Set 1
airCraftParts = {"Wheels","Engine","Gear","Wings","Tail"}
# Set 2
carParts = {"Wheels","Engine","Gear"}
# Set 1 ∩ Set 2
automobileParts = airCraftParts.intersection(carParts)
print("Intersection of two sets:")
print(automobileParts)Output
Intersection of two sets:
{'Gear', 'Engine', 'Wheels'}