w3resource logo


Python Exercises

Python Exercise: 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)

Output :

{'mango'}
{'apple'}

Python Code Editor:

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

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program