The difference operation compares two sets and returns a set containing the elements that are in the first set but not in the second set. The difference operator - uses this syntax:

The difference method uses this syntax:


The following example finds the set of round things that aren't pink:

>>> roundthings = ['orange',


'egg', 'tire']

>>> pinkthings = ['lipstick'

, 'gumball',

'baby blanket']

>>> a = set(roundthings)

>>> q = set(pinkthings)

>>> a - q

set(['orange', 'egg', 'tire'


Was this article helpful?

0 0

Post a comment