Python Set Intersection() 메서드
예시
x
set 과 set 에 모두 존재하는 항목을 포함하는 세트를 반환합니다
y
.
x =
{"apple", "banana", "cherry"}
y = {"google",
"microsoft", "apple"}
z = x.intersection(y)
print(z)
정의 및 사용
이 intersection()
메서드는 둘 이상의 집합 간의 유사성을 포함하는 집합을 반환합니다.
의미: 반환된 집합에는 두 집합에 모두 존재하는 항목만 포함됩니다.
통사론
set.intersection(set1, set2 ... etc)
매개변수 값
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 |
더 많은 예
예시
3세트를 비교하고 3세트 모두에 있는 항목이 포함된 세트를 반환합니다.
x =
{"a", "b", "c"}
y = {"c",
"d", "e"}
z = {"f",
"g", "c"}
result = x.intersection(y, z)
print(result)