Definition
The intersection() method returns a set that contains the similarity between two or more sets. The returned set contains only items that exist in both sets, or in all sets if the comparison is done with more than two sets.
Syntax
set.intersection(set1, set2 ... etc)
Parameters
Parameter | Description |
---|---|
set1 | Required. The set to search for equal items in |
set2... | Optional. The other set to search for equal items in. You can compare as many sets you like. Separate the sets with a comma. |
Examples:
persons1 = {"Mark", "Jeff", "Ivan", "Mike"}
persons2 = {"Arnel", "Marie", "Ivan", "Alex"}
persons = persons1.intersection(persons2)
print(persons)
# example with 3 sets
persons1 = {"Mark", "Jeff", "Ivan", "Mike"}
persons2 = {"Arnel", "Marie", "Ivan", "Alex"}
persons3 = {"Ivan", "Cindy", "Sarah", "Igor"}
persons = persons1.intersection(persons2, persons3)
print(persons)