Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




symmetric_difference_update( ) FUNCTION


As the name suggests, the 'symmetric_difference_update( )' Function takes those values that are not present in both the sets.


Example :


x = {"Mohan", "Kriti", "Salim"}
y = {"Sia", "Andrew", "Kriti"}
x.symmetric_difference_update(y)
print(x) 


Output :



  {'Andrew', 'Sia', 'Salim', 'Mohan'}

So, in the above code we have created a 'Set' and initialised to the variable 'x'.


x = {"Mohan", "Kriti", "Salim"}

java_Collections

Then what we have done is, put the names, 'Sia', 'Andrew' and 'Kriti' in another set 'y'.


y = {"Sia", "Andrew", "Kriti"}

java_Collections

And used the 'symmetric_difference_update( )' Function next.


x.symmetric_difference_update(y)

And since, 'Kriti' is present in both the Sets, only 'Kriti' would be excluded in the Set 'x'.Rest of the values would be taken.


java_Collections

And we get the below output,


{'Andrew', 'Sia', 'Salim', 'Mohan'}