Python Set update() Method Tutorial

In this section, we will learn what the Set update() method is and how to use it in Python.

What is Set update() Method in Python?

The Python Set update() method is used to update a Set object by adding the content of another set or any other iterable object.

Note: this other iterable object if it had an element that is already in the original Set (the one that invoked this method) that element will be ignored.

Python Set update() Method Syntax:

set.update(referenceIterable)

Set update() Method Parameter:

The method takes one argument and that is a reference to a Set object (or an iterable object in general) that we want to copy and move its unique elements to the original Set.

Set update() method Return Value

The method does not return a value.

Example: using python set update() method

set1 = {1,2,3,4,5,6,7,8,9,10}

set2 = {1,2,3,4,5,500,600,700}

set1.update(set2)

print(set1)

Output:

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 500, 600, 700}
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies