Created
February 18, 2020 07:52
-
-
Save y56/12b573d0f82abfd1d6f19dbd86d517b2 to your computer and use it in GitHub Desktop.
Python | remove() and discard() in Sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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