Set Methods
set.remove()
Mutates the original set, so aliases observe the change. Delete the member matching the supplied value. Missing members raise KeyError; use discard for optional removal. A mutable set may serve as a lookup for an equivalent stored frozenset. The operation can also fail if hashing or equality fails; it is not positional deletion.
Formal Syntax & Structure
python syntaxpython
items.remove(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
No removed value is returned.
Working Example
Example Snippetpython
pending = {"draft", "review"}pending.remove("draft")print(sorted(pending))try: pending.remove("draft")except KeyError: print("already absent")