With the intersection of sets, the intersection update() method updates the set using the intersection update() method. The set of elements that are common to all sets is the intersection of two or more sets. The intersection update() function differs from the intersection() method in that it returns a new set without the undesired elements, whereas the intersection() method delivers the original set with the unwanted things removed.
intersection_update() Parameters
An arbitrary number of arguments(sets) can be passed to the intersection update() method.
Return Value from Intersection_update()
No value is returned by this procedure (meaning it does not have a return value). It merely calls the intersection update() method to update the set. For example:
result = A.intersection_update(B, C)
When you run the code,
- result will be None
- A will be equal to the intersection of A, B, and C
- B remains unchanged
- C remains unchanged
Example 1: How intersection_update() Works?
A = {1, 2, 3, 4} B = {2, 3, 4, 5} result = A.intersection_update(B) print('result =', result) print('A =', A) print('B =', B) Output
result = None
A = {2, 3, 4}
B = {2, 3, 4, 5}
Example 2: intersection_update() with Two Parameters
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)
Output
result = None
C = {4}
B = {2, 3, 4, 5, 6}
A = {1, 2, 3, 4}
Leave a Reply