Menu Close

Python Set difference_update Method

python set difference_update

In this tutorial, you will learn all about Python set difference_update. Python set difference_update method is used to remove items which exists in both sets. difference_update method is a built-in set method, which only used with python set.

In the previous tutorial, we have seen Python set clear method to remove all items from the set. To understand this tutorial, you should have basic knowledge of the Python set.

Python set difference_update method

Python set difference_update method is a built-in set method which used to remove items that exists in both sets.

Syntax

The syntax of difference_update function in Python is:-

set.difference_update(set)

Parameter

The difference_update function in python accepts one parameter that is set.

  • set:- Required. The set to check for difference.

Return Value

difference_update function in Python update existing set.

Python set difference_update example

Here we will take some examples to understand difference_update in python.

Example 2:

x = {'Python', 'C++', 'C', 'C#'}
y = {'HTML', 'C++', 'CSS', 'Bootstrap'}

x.difference_update(y)
print(x)

Output

{'C', 'C#', 'Python'}

Conclusion

In this tutorial, you have learned difference_update in python. difference_update function in Python return remove items which exists in both sets.

I hope this tutorial will help you. If you like this article, please share it with your friends who want to learn Python programming.

Other set methods


For More Information:- Click Here

Python Set difference Method
Python Set copy() Method

Related Posts