symmetric_difference_update() function in python by R4R Team

- symmetric_difference_update() is a python function which is only applicable on sets.
- It find the symmetric difference of two sets and update the one set.

Syntax-

set1.symmetric_difference_update(set2)

- It erase the common elements from the both the sets and update set1 with rest of elements.

Example

set1 is {1,2,3,4,5}
set2 is {3,4,5,6,7}

it will update the set1 of value is {1,2,6,7}


program-

set1={1,2,3,4}
set2={3,4,5,6,7,8,9}

print("Set1 is",set1)
print("Set2 is",set2)
print(set1.symmetric_difference_update(set2))
print("Now Set1 is",set1)
print("Now Set2 is",set2)

set1={1,2,3,4}
set2={3,4,5,6,7,8,9}

print(set2.symmetric_difference_update(set1))
print("Now Set1 is",set1)
print("Now Set2 is",set2)


output-

Set1 is {1, 2, 3, 4}
Set2 is {3, 4, 5, 6, 7, 8, 9}
None
Now Set1 is {1, 2, 5, 6, 7, 8, 9}
Now Set2 is {3, 4, 5, 6, 7, 8, 9}
None
Now Set1 is {1, 2, 3, 4}
Now Set2 is {1, 2, 5, 6, 7, 8, 9}


-In this program, we have two sets and we find the symmetric difference and update the one set with symmetric difference.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!