How to Use Set intersection_update() Method in PythonPython Basics


The intersection_update() method updates the calling set with the intersection sets.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

A = {1,2,3}
B = {1,4,5,6,11}
C = {1,2,11}

A.intersection_update(B)
B.intersection_update(C)
print("The  set A  is",A)
print("The  set B  is",B)

Output:

The  set A  is {1}
The  set B  is {1, 11}

Syntax

set_x.intersection_update(*other_sets)

Parameters

Name Description
set_x A set
*other_sets *other_sets denotes the arbitrary number of arguments.

Return Value

It doesn’t return any value.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us