Home >>Python Set Methods >Python Set add() Method
Python set add() method is used to add an element to the given input set. If the element already exists then the add() method does not add the element.
Syntax:set.add(element)
Parameter | Description |
---|---|
element | This is a required parameter. It defines the element to add to the set. |
thisset = {"apple", "banana", "mango"}
thisset.add("orange")
print(thisset)
thisset = {"apple", "banana", "mango"}
thisset.add("mango")
print(thisset)