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




symmetric_difference( ) FUNCTION


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


Example :


x = {"Mohan", "Kriti", "Salim"}
y = {"Sia", "Andrew", "Kriti"}
z = x.symmetric_difference(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( )' Function next.


z = x.symmetric_difference(y)

And since, 'Kriti' is present in both the Sets, only 'Kriti' would be excluded in the new Set 'z'.


Rest of the values would be taken.


java_Collections

And we get the below output,


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