{"id":25376,"date":"2022-01-03T09:10:18","date_gmt":"2022-01-03T03:40:18","guid":{"rendered":"https:\/\/python-programs.com\/?p=25376"},"modified":"2022-01-03T09:10:18","modified_gmt":"2022-01-03T03:40:18","slug":"python-set-symmetric_difference_update-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-set-symmetric_difference_update-method-with-examples\/","title":{"rendered":"Python Set symmetric_difference_update() Method with Examples"},"content":{"rendered":"

Set symmetric_difference_update() Method:<\/strong><\/p>\n

The symmetric_difference_update() method updates the original set by removing items from both sets and inserting new items.<\/p>\n

The set of elements that are in either P or Q but not in their intersection is the symmetric difference of two sets P and Q.<\/p>\n

For Example:<\/strong><\/p>\n

If P and Q are two distinct sets. The symmetric_difference_update of the given two sets is :<\/p>\n

Let P={4, 5, 6, 7}<\/p>\n

Q={5, 6, 8, 9}<\/p>\n

Here {5, 6} are the common elements in both sets.<\/p>\n

so, Set P is updated with all the other items from both sets except the common elements.<\/p>\n

Set Q, on the other hand, remains unchanged.<\/p>\n

Output : P={4, 7, 8, 9} and Q={5, 6, 8, 9}<\/p>\n

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

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

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

set:<\/strong> This is Required. The set to look for matches in.<\/p>\n

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

None is returned by symmetric difference update() (returns nothing). Rather, it calls the set and updates it.<\/p>\n

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

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

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

Given first set = {10, 20, 50, 60, 30}\r\nGiven second set = {20, 30, 80, 90}<\/pre>\n

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

The given first set =  {10, 80, 50, 90, 60}\r\nThe given second set =  {80, 90, 20, 30}\r\nThe result after applying symmetric_difference_update() method =  None<\/pre>\n

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

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

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

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

The given first set =  {'d', 'e'}\r\nThe given second set =  {'a', 'e', 'b', 'd', 'c'}\r\nThe result after applying symmetric_difference_update() method =  None<\/pre>\n

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