Python 교차_업데이트() 메서드 설정
예시
x
및 모두에 없는 항목을 제거합니다 y
.
x =
{"apple", "banana", "cherry"}
y = {"google",
"microsoft", "apple"}
x.intersection_update(y)
print(x)
정의 및 사용
이 intersection_update()
방법은 두 세트(또는 두 세트 이상의 세트 간에 비교가 수행되는 경우 모든 세트)에 없는 항목을 제거합니다.
이 방법은 원하지 않는 항목 없이
새 집합을 반환 하고 원래 집합에서 원하지 않는 항목을 제거 하기 때문에 방법과
다릅니다 intersection_update()
.intersection()
intersection()
intersection_update()
통사론
set.intersection_update(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"}
x.intersection_update(y, z)
print(x)