Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Intersection() 함수 파이썬

<시간/>

이 기사에서는 주어진 집합에서 수행할 수 있는 Intersection() 함수에 대해 배울 것입니다. 수학 교집합에 따르면 두 집합에서 공통 요소를 찾는 것을 의미합니다.

Intersection() 함수 파이썬

구문

<set name>.intersection(<set a1> <set a2> ……..)

반환 가치

인수로 전달된 세트의 공통 요소.

예시

set_1 = {'t','u','t','o','r','i','a','l'}
set_2 = {'p','o','i','n','t'}
set_3 = {'t','u','t'}
#intersection of two sets
print("set1 intersection set2 : ", set_1.intersection(set_2))
# intersection of three sets
print("set1 intersection set2 intersection set3 :", set_1.intersection(set_2,set_3))

출력

set1 intersection set2 : {'i', 'o', 't'}
set1 intersection set2 intersection set3 : {'t'}

설명

여기서 인터프리터에 의해 암시적으로 공통 요소를 찾기 위해 검색이 수행되고 해당 참조에 대한 집합으로 다시 반환됩니다.

결론

이 기사에서 우리는 Python 3.x에 있는 교차 함수의 구현 및 사용에 대해 배웠습니다. 또는 그 이전.