Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 15, 2020 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/8d349f5102b3ad2c317f6fac299cb2eb to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/8d349f5102b3ad2c317f6fac299cb2eb to your computer and use it in GitHub Desktop.
s1={1,2,3,4,5}
s2={4,5,6,7,8}
#difference using operator -
s3=s1-s2
print (s3) #Output: {1,2,3}
s4=s1.difference(s2)
print (s4) #Output: {1,2,3}
#difference_update() will modify the original set. Return type is None.
s1.difference_update(s2)
print (s1) #Output: {1,2,3}
# difference_update by using -= operator
s2-=(s1)
print (s2) #Output: {4,5,6,7,8}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment