Set Methods
set.add()
Mutates the original set, so aliases observe the change. Insert one hashable object if no equal element is already present. Adding the same value again does not increase cardinality. A tuple is inserted as one element rather than expanded; use update to consume an iterable. A mutable set or list cannot itself be added. Hashing and equality may raise exceptions.
Formal Syntax & Structure
python syntaxpython
items.add(elem, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| elem | Hashable | Element to add. |
Return Value
None
No new set is returned.
Working Example
Example Snippetpython
tags = {"draft"}alias = tagsprint(tags.add("review"))tags.add("draft")print(sorted(alias))