Python Set discard() Method
Last Updated : 17 Mar 2025
Python discard() method discards or remove the elememt from the set. This method does not return anything, even no error if the elememt is not present. It takes a parameter which is an elememt to be removed. The method signature is given below.
Signature
Parameters
elem: element to be deleted.
Return
It returns None.
Let's see some examples of discard() method to understand it's functionality.
Python Set discard() Method Example 1
A simple example to use discard method to remove an element.
Output:
{1, 2, 3, 4, 5}
{1, 3, 4, 5}
Python Set discard() Method Example 2
If the element is not present it returns none to the caller method.
Output:
Python Set discard() Method Example 3
An example where we are implementing this method into a program. It removes all odds elements.
Output: