Skip to content

Instantly share code, notes, and snippets.

@y56
Created February 18, 2020 07:52
Show Gist options
  • Save y56/12b573d0f82abfd1d6f19dbd86d517b2 to your computer and use it in GitHub Desktop.
Save y56/12b573d0f82abfd1d6f19dbd86d517b2 to your computer and use it in GitHub Desktop.
Python | remove() and discard() in Sets
https://www.geeksforgeeks.org/python-remove-discard-sets/
Method 1: Use of discard() method
The built-in method, discard() in Python, removes the element from the set only if the element is present in the set. If the element is not present in the set, then no error or exception is raised and the original set is printed.
If the element is present in the set:
Method 2: Use of remove() method
The built-in method, remove() in Python, removes the element from the set only if the element is present in the set, just as the discard() method does but If the element is not present in the set, then an error or exception is raised.
If the element is present in the set:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment