Home >>Python Set Methods >Python Set update() Method

Python Set update() Method

Python Set update() Method

Python set update() method is used to update the current set by adding items to it from the another set. If an item is present in both sets then only one appearance of this item will be present in the updated set.

Syntax:
set.update(set)

Parameter Values

Parameter Description
set This is a required parameter. It defines the set insert into the current set.
Here is an example of Python update() method:

x = {"Abhi", "Jerry", "Mickey"}
y = {"Wings", "Alpha", "Jerry"}
x.update(y) 
print(x)

Output:
{'Jerry', 'Wings', 'Mickey', 'Alpha', 'Abhi'}
Example 2:

x = {"Abhi", "Jerry", "Mickey"}
y = {"Wings", "Alpha", "Jerry"}
y.update(x) 
print(y)

Output:
{'Wings', 'Abhi', 'Jerry', 'Mickey', 'Alpha'}

Popular Tutorials