Set Update() Method in Python

Python set update() method updates the current set by inserting items of other set elements. If the items of another set are already present in the current, only one item will be present in the resulting set.


set.update(set1, set2,…)

Parameter Description

Name Description
set Specify the main set to which the other set will be added
set1 Required. To insert into the main set.
set2 optional. Another set in comma separation to add to the set. You can add as many sets as you want to the main set.

Let’s find out the use of the Python set update() Function with the examples given below.

Examples of Python Set update() Function

When you update one set to another set in Python, the sequence of resulting items is not in sequence. Every time you refresh the code, you will get a different sequence of sets in each execution.

Example 1


{‘jQuery’, 1, 2, 3, 4, ‘CSS’, ‘PHP’, ‘HTML’, ‘javascript’}

In the above example add a set b to the main set a.

Similarly, you can add another set to the main set of items. Just add another set in comma-separation as given in the example below.

Example 2


{1, ‘PHP’, ‘javascript’, 2, 3, 4, ‘jQuery’, ‘HTML’, ‘z’, ‘CSS’, ‘x’, ‘y’}

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.