Definition
The add() method adds an element to the set. If the element already exists, the method does not add the element.
Syntax
set.add(item)
Parameters
Parameter | Description |
---|---|
item | Required. The element to add to the set |
Examples:
persons = {"Mark", "Jeff", "Ivan", "Mike"}
persons.add("Alex")
print(persons)
# adding an element that already exists
persons = {"Mark", "Jeff", "Ivan", "Mike"}
persons.add("Jeff")
print(persons)