w3resource logo
Python Exercises

Python Exercise: Create set difference

Python sets: Exercise-8 with Solution

Write a Python program to create set difference.

Sample Solution:-

Python Code:

setx = set(["apple", "mango"])
sety = set(["mango", "orange"])
setz = setx & sety
print(setz)
#Set difference
setb = setx - setz
print(setb)

Sample Output:

{'mango'}                                                                                                     
{'apple'} 

Python Code Editor:

Improve this sample solution and post your code through Disqus