English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
intersection_update() uses the intersection of sets to update the set that calls intersection_update().
The intersection of two or more sets is the set of elements common to all sets.
For more information, please visitPython set Intersection.
junction_update() syntax is:
A.intersection_update(*other_sets)
intersection_update() allows an arbitrary number of parameters (sets).
Note: *Is not part of the syntax. It is used to indicate that this method allows an arbitrary number of parameters.
This method returns None (meaning, no return value). It only updates the set that calls the intersection_update() method.
Assuming,
result = A.intersection_update(B, C)
When you run the code:
result will be None
A equals the intersection of A, B, and C
B remains unchanged
C remains unchanged
A = {1, 2, 3, 4} B = {2, 3, 4, 5} result = A.intersection_update(B) print('result =', result) print('A =', A) print('B =', B)
When running this program, the output is:
result = None A = {2, 3, 4} B = {2, 3, 4, 5, 6}
A = {1, 2, 3, 4} B = {2, 3, 4, 5, 6} C = {4, 5, 6, 9, 10} result = C.intersection_update(B, A) print('result =', result) print('C =', C) print('B =', B) print('A =', A)
When running this program, the output is:
result = None C = {4} B = {2, 3, 4, 5, 6} A = {1, 2, 3, 4}