Methods and Functions

Python Set intersection_update()

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

Source

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}
 
Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.