YouTip LogoYouTip

Ref Set Difference

# Python3.x Python Set difference() Method [![Image 3: Python3 Lists](#) Python Sets](#) * * * ## Description The `difference()` method is used to return the difference of sets, i.e., it returns a set containing elements that are in the first set but not in the second set (the method's parameter). ## Syntax The syntax for the `difference()` method is: set.difference(set) ## Parameters * set -- Required, the set used to compute the difference. ## Return Value Returns a new set. ## Example Returns a set containing elements that are in set `x` but not in set `y`: ## Example 1 x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"} z = x.difference(y)print(z) The output result is: {'cherry', 'banana'} [![Image 4: Python3 Lists](#) Python Sets](#)
← Ref Set DiscardRef Set Clear β†’