w3resource logo
Python Exercises

Python Exercise: Create a symmetric difference

Python sets: Exercise-9 with Solution

Write a Python program to create a symmetric difference.

Sample Solution:-

Python Code:


setx = set(["apple", "mango"])
sety = set(["mango", "orange"])
#Symmetric difference
setc = setx ^ sety
print(setc)

Sample Output:

{'apple', 'orange'}

Python Code Editor:

setx = set(["apple", "mango"])
sety = set(["mango", "orange"])
#Symmetric difference
setc = setx ^ sety
print(setc)

Improve this sample solution and post your code through Disqus