Phương thức
A.intersection[*other_sets]4 trả về một tập hợp mới với các phần tử phổ biến cho tất cả các tập hợp.
Thí dụ
A = {2, 3, 5}
B = {1, 3, 5}
# compute intersection between A and B
print[A.intersection[B]]
# Output: {3, 5}
Cú pháp của SET Intersection []
Cú pháp của
A.intersection[*other_sets]4 trong Python là:
A.intersection[*other_sets]
Các tham số giao nhau []
A.intersection[*other_sets]4 cho phép số lượng đối số [bộ] tùy ý.
Lưu ý: * không phải là một phần của cú pháp. Nó được sử dụng để chỉ ra rằng phương pháp cho phép số lượng đối số tùy ý. * is not part of the syntax. It is used to indicate that the method allows arbitrary number of arguments.
Trả về giá trị từ giao lộ []
Phương thức
A.intersection[*other_sets]4 Trả về giao điểm của Set A với tất cả các tập hợp [được truyền làm đối số].
Nếu đối số không được chuyển cho
A.intersection[*other_sets]4, nó sẽ trả về một bản sao nông của bộ [a].
Ví dụ 1: Giao lộ Set Python []
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
Đầu ra
{2, 5} {2} {2, 3} {2}
Hoạt động của Set Intersection []
Giao điểm của hai hoặc nhiều bộ là tập hợp các phần tử phổ biến cho tất cả các bộ. Ví dụ:
A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}phân định ba bộ
Nhiều ví dụ hơn
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3}
D = {100, 200, 300}
print[A.intersection[D]]
print[B.intersection[D]]
print[C.intersection[D]]
print[A.intersection[B, C, D]]
Đầu ra
{100} {200} {300} set[]
Hoạt động của Set Intersection []
Giao điểm của hai hoặc nhiều bộ là tập hợp các phần tử phổ biến cho tất cả các bộ. Ví dụ:
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
Đầu ra
{7} {100} set[] set[]
❮ Đặt phương pháp
Thí dụ
Trả về một tập hợp chứa các mục tồn tại trong cả bộ
A.intersection[*other_sets]9 và đặt
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
0: x = {"Apple", "Banana", "Cherry"} y = {"Google", "Microsoft", "Apple"}
y = {"google", "microsoft", "apple"}
z = x.interection [y]
print[z]
Hãy tự mình thử »
Định nghĩa và cách sử dụng
Phương thức
A.intersection[*other_sets]4 trả về một tập hợp chứa sự tương đồng giữa hai hoặc nhiều bộ.
Ý nghĩa: Bộ được trả về chỉ chứa các mục tồn tại trong cả hai bộ hoặc trong tất cả các bộ nếu so sánh được thực hiện với nhiều hơn hai bộ.
Cú pháp
set.interection [set1, set2 ... vv]]
Giá trị tham số
Hiệp 1 | Yêu cầu. Bộ để tìm kiếm các mục bằng nhau trong |
set2 | Không bắt buộc. Một bộ khác để tìm kiếm các mục bằng nhau trong. Bạn có thể so sánh càng nhiều bộ bạn thích. Xác định các bộ với dấu phẩy You can compare as many sets you like. Separate the sets with a comma |
Nhiều ví dụ hơn
Thí dụ
Trả về một tập hợp chứa các mục tồn tại trong cả bộ
A.intersection[*other_sets]9 và đặt
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
0: x = {"Apple", "Banana", "Cherry"} y = {"Google", "Microsoft", "Apple"}
y = {"c", "d", "e"}
z = {"f", "g", "c"}
z = x.interection [y]
print[result]
Hãy tự mình thử »
❮ Đặt phương pháp
Phương thức Python Set Intersection [] trả về một tập mới với một phần tử phổ biến cho tất cả các tập hợp a new set with an element that is common to all set
Giao điểm của hai bộ đã cho là bộ lớn nhất, chứa tất cả các yếu tố phổ biến cho cả hai bộ. Giao điểm của hai bộ A và B đã cho là một tập hợp bao gồm tất cả các yếu tố phổ biến cho cả A và B.common to both sets. The intersection of two given sets A and B is a set which consists of all the elements which are common to both A and B.
Python Set Intersection [] Phương thức Cú pháp:
Cú pháp: set1.intersection [set2, set3, set4.] & Nbsp; tham số:set1.intersection[set2, set3, set4….]
Parameters:
- Bất kỳ số lượng bộ nào cũng không thể & nbsp; được thông qua
Trả về: Trả về một tập hợp có giao điểm của tất cả các bộ [SET1, SET2, SET3,] với SET1. Nó chỉ trả về một bản sao của Set1 nếu không có tham số nào được truyền. & Nbsp; Returns a set which has the intersection of all sets[set1, set2, set3…] with set1. It returns a copy of set1 only if no parameter is passed.
Python Set Intersection [] Phương thức Ví dụ:
Python3
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
2A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
5A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
7A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
9{2, 5} {2} {2, 3} {2}0
{2, 5} {2} {2, 3} {2}1
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
7A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
9{2, 5} {2} {2, 3} {2}0
{2, 5} {2} {2, 3} {2}8
{2, 5} {2} {2, 3} {2}9
Output:
{2, 3}
Ví dụ 1: Hoạt động của Set Intersection []
Python3
A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}0
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
7A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}7
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
{2, 5} {2} {2, 3} {2}0
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3}
D = {100, 200, 300}
print[A.intersection[D]]
print[B.intersection[D]]
print[C.intersection[D]]
print[A.intersection[B, C, D]]
1A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3}
D = {100, 200, 300}
print[A.intersection[D]]
print[B.intersection[D]]
print[C.intersection[D]]
print[A.intersection[B, C, D]]
8A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6{100} {200} {300} set[]0
{2, 5} {2} {2, 3} {2}0
{100} {200} {300} set[]2
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6{100} {200} {300} set[]0
{2, 5} {2} {2, 3} {2}0
{2, 5} {2} {2, 3} {2}8
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
2A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
3A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
4A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
5A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
6{2, 5} {2} {2, 3} {2}8
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
2A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
9A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
4A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
5{7} {100} set[] set[]2
Output:
A.intersection[*other_sets]0
Ví dụ 2: Toán tử giao nhau đặt Python [&]
Chúng ta cũng có thể nhận được các giao lộ bằng toán tử ‘&.
Python3
A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}0
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
7A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}7
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
{2, 5} {2} {2, 3} {2}0
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3}
D = {100, 200, 300}
print[A.intersection[D]]
print[B.intersection[D]]
print[C.intersection[D]]
print[A.intersection[B, C, D]]
1A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3}
D = {100, 200, 300}
print[A.intersection[D]]
print[B.intersection[D]]
print[C.intersection[D]]
print[A.intersection[B, C, D]]
8A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6{100} {200} {300} set[]0
{2, 5} {2} {2, 3} {2}0
{100} {200} {300} set[]2
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6{100} {200} {300} set[]0
{2, 5} {2} {2, 3} {2}0
{2, 5} {2} {2, 3} {2}8
A.intersection[*other_sets]15
{2, 5} {2} {2, 3} {2}8
A.intersection[*other_sets]17
{2, 5} {2} {2, 3} {2}8
A.intersection[*other_sets]19
Output:
A.intersection[*other_sets]1
Ví dụ 2: Toán tử giao nhau đặt Python [&]
Chúng ta cũng có thể nhận được các giao lộ bằng toán tử ‘&.
Python3
A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}0
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
7A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}7
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
{2, 5} {2} {2, 3} {2}0
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3}
D = {100, 200, 300}
print[A.intersection[D]]
print[B.intersection[D]]
print[C.intersection[D]]
print[A.intersection[B, C, D]]
1A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3}
D = {100, 200, 300}
print[A.intersection[D]]
print[B.intersection[D]]
print[C.intersection[D]]
print[A.intersection[B, C, D]]
8A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6{100} {200} {300} set[]0
{2, 5} {2} {2, 3} {2}0
{100} {200} {300} set[]2
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}5
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A = {1, 2, 3, 4} B = {2, 3, 4, 9} C = {2, 4, 9 10} Then, A∩B = B∩A ={2, 3, 4} A∩C = C∩A ={2, 4} B∩C = C∩B ={2, 4, 9} A∩B∩C = {2, 4}9
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6{100} {200} {300} set[]0
{2, 5} {2} {2, 3} {2}0
{2, 5} {2} {2, 3} {2}8
A.intersection[*other_sets]52
{2, 5} {2} {2, 3} {2}8
A.intersection[*other_sets]54
{2, 5} {2} {2, 3} {2}8
A.intersection[*other_sets]56
Output:
A.intersection[*other_sets]2
Ví dụ 2: Toán tử giao nhau đặt Python [&]
Chúng ta cũng có thể nhận được các giao lộ bằng toán tử ‘&.
Python3
{100} {200} {300} set[]2
A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
3 A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
4A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
5A = {2, 3, 5, 4}
B = {2, 5, 100}
C = {2, 3, 8, 9, 10}
print[B.intersection[A]]
print[B.intersection[C]]
print[A.intersection[C]]
print[C.intersection[A, B]]
6A.intersection[*other_sets]10__26
A.intersection[*other_sets]122
Ví dụ 3: Giao điểm bộ Python đối diện
{2, 5} {2} {2, 3} {2}8
A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
2A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
3A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
4A = {100, 7, 8}
B = {200, 4, 5}
C = {300, 2, 3, 7}
D = {100, 200, 300}
print[A & C]
print[A & D]
print[A & C & D]
print[A & B & C & D]
5A.intersection[*other_sets]68
A.intersection[*other_sets]69
A.intersection[*other_sets]68
A.intersection[*other_sets]71
Output:
A.intersection[*other_sets]3