{"id":25067,"date":"2021-11-10T09:37:41","date_gmt":"2021-11-10T04:07:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=25067"},"modified":"2021-11-10T09:37:41","modified_gmt":"2021-11-10T04:07:41","slug":"python-set-update-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-set-update-method-with-examples\/","title":{"rendered":"Python Set update() Method with Examples"},"content":{"rendered":"
Prerequisite:<\/h5>\n

Python set() Function with Examples<\/span><\/a><\/p>\n

Set update() Method in Python:<\/strong><\/p>\n

The update() method adds items from another set to the current set (or any other iterable).<\/p>\n

If an item appears in both sets, only one appearance will appear in the updated set.<\/p>\n

Syntax:<\/strong><\/p>\n

set.update(set)<\/pre>\n

Parameters<\/strong><\/p>\n

set:<\/strong> This is Required. It is iterable to be inserted into the current set.<\/p>\n

Return Value:<\/strong><\/p>\n

None is returned by the set update() method (returns nothing).<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first set =  {'a', 'b', 'c'}\r\nGiven second set = {'b', 'p', 'q'}<\/pre>\n

Output:<\/strong><\/p>\n

The given first set after updating is : {'p', 'q', 'b', 'a', 'c'}\r\nThe given second set is : {'p', 'q', 'b'}\r\nThe result after applying the update() method:  None<\/pre>\n

Explanation:<\/strong><\/p>\n

Here, add items of the second set to the first set and update it.\r\nBut 'b' appears in both sets, only one appearance of 'b' will appear in the \r\nupdated first set.<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first set = {9, 11, 2, 6}\r\nGiven second set = {2, 1, 3, 9}<\/pre>\n

Output:<\/strong><\/p>\n

The given first set is : {9, 2, 11, 6}\r\nThe given second set after updating is : {1, 2, 3, 6, 9, 11}\r\nThe result after applying the update() method: None<\/pre>\n

Set update() Method with Examples in Python<\/h2>\n