Python Set discard() Syntax

set.discard(element)

Parameter
element – an item to remove from the set.

Return Value
return  – discard() method doesn’t return any value.

Python Set discard() Function

Python discard() is a built-in method to remove elements from the set. The discard() method takes exactly one argument. This method does not return any value.

Example: In this example, we are removing the integer 3 from the set with discard() in Python.

Python3




my_set = {1, 2, 3, 4, 5}
my_set.discard(3
print(my_set)


Output

{1,2,4,5}

Similar Reads

Python Set discard() Syntax

...

Python Set discard() Examples

set.discard(element) Parameterelement – an item to remove from the set. Return Valuereturn  – discard() method doesn’t return any value....

Contact Us