×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python Set intersection_update() Method (with Examples)

Last Updated : December 11, 2025

Python Set intersection_update() Method

The intersection_update() is an inbuilt method of the set class that is used to update the original set with the common elements which exist in all sets i.e., we can say intersection_update() is used to remove unwanted elements (which are not available in all sets).

Syntax

The following is the syntax of intersection_update() method:

set1.intersection_update(set1, set2, set3, ...)

Parameter(s):

The following are the parameter(s):

  • set1 – It represents the set to be compared with this set.
  • set2, set3, ... – These are optional sets, we can provide multiple sets to be compared.

Return Value

The return type of this method is <class 'NoneType'>, it returns nothing.

Example 1: Use of Set intersection_update() Method

# declaring the sets
cars_1 = {"Porsche", "Audi", "Lexus"}
cars_2 = {"Porsche", "Mazda", "Lincoln"}

# before method call 
print("Before intersection_update() method call...")
print("cars_1:", cars_1)
print("cars_2:", cars_2)

# intersection_update() method call
cars_1.intersection_update(cars_2)

# printing the set after method call
print("After intersection_update() method call...")
print("cars_1:", cars_1)
print("cars_2:", cars_2)

Output

Before intersection_update() method call...
cars_1: {'Lexus', 'Porsche', 'Audi'}
cars_2: {'Lincoln', 'Porsche', 'Mazda'}
After intersection_update() method call...
cars_1: {'Porsche'}
cars_2: {'Lincoln', 'Porsche', 'Mazda'}

Example 2: Use of Set intersection_update() Method

# declaring the sets
x = {"ABC", "PQR", "XYZ"}
y = {"ABC", "PQR", "XYZ"}
z = {"DEF", "MNO", "ABC"}

# printing the results
print("x:", x)
print("y:", y)
print("z:", z)

# printing the common elements
x.intersection_update(y,z)
print("x: ",x)

Output

x: {'XYZ', 'PQR', 'ABC'}
y: {'XYZ', 'PQR', 'ABC'}
z: {'MNO', 'ABC', 'DEF'}
x:  {'ABC'}
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.