set.discard() in python



"discard()" function is used to remove the specified element in the set. It will not show error if the specified element is not available in the set.



Syntax:




set.discard(value)







Example-1
n = {10, 30, 50}

n.discard(30)

print(n)


Output



{10, 50}







Example-2
n = {10, 30, 50}

n.discard(20)

print(n)


Output



{10, 50, 30}







Example-3
n = {"A", "B", "AB", "A"}

n.discard("A")

print(n)


Output



{'B', 'AB'}