This method is used to remove the particular item from the set, by taking that item as argument. Since the item is discarded from the ordinal set, therefore all changes are done in original set itself.
Important part of this method is that it does not throw an error if specified item is not present inside set.
This method takes an argument.
- A set is taken
- discard() method is being applied to it and an item is passed
- set is printed after discarding the particular element
- The set without apple value is printed.
- What is the difference between discard method and remove method in set?
discard() method removes the specified item from set but if the specified item is not present it does not throw an error. remove() method is used to remove and delete the specified item but if the specified item is not present it throws an error.