Set Methods
set.discard()
Mutates the original set, so aliases observe the change. Delete the member matching the supplied value if present; absence is not an error. A set argument can match a stored frozenset with the same members. This special lookup rule does not permit inserting unhashable sets as members. Other invalid lookup keys or failures in hashing/equality can still raise exceptions. Use remove when absence should be reported.
Formal Syntax & Structure
python syntaxpython
items.discard(elem, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| elem | Hashable | set | Element to locate; a set can be used to search for an equivalent frozenset. |
Return Value
None
Returns None regardless of whether a member existed.
Working Example
Example Snippetpython
active = {"red", "blue"}print(active.discard("red"))active.discard("missing")print(sorted(active))