Menu Close

Python Set update Method

Python set update

In this set method tutorial, we will learn all about Python set update method. Set update function in python is used to update the current set by adding items from another set.
You should have a basic knowledge of the Python set, To understand this set method.

Python Set update() Method

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

Syntax

The syntax of update function in python is:-

set.union(set)

Parameter

The set update in python accepts one parameter:-

  • set – Required. The set insert into current set.

Return value

set update function in python does not return new set, it updates original set.

Python set update example

Update current set by adding items items from another set.

Example:

set1 = { 'Python', 'Java', 'JavaScript', 'C++'}
set2 = {'Python', 'HTML', 'JavaScript', 'Bootstrap'}
set1.update(set2)
print(set1)

Output

{'Python', 'Bootstrap', 'Javascript', 'HTML', 'C++', 'Java'}

Conclusion

In this article, you have learned all about the python set update method. set update python to update the current set by adding items from another set.

If you like this article, keep visiting and learn your Python’s more topics.

Other set methods


For more information:- Click here

Previous Article
Next Article

Related Posts

Leave a Reply