Home >>Python Set Methods >Python Set add() Method

Python Set add() Method

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 Values

Parameter Description
element This is a required parameter. It defines the element to add to the set.
Here is an example of Python add() method:

thisset = {"apple", "banana", "mango"}
thisset.add("orange")
print(thisset)

Output:
{'banana', 'apple', 'orange', 'mango'}
Example 2:

thisset = {"apple", "banana", "mango"}
thisset.add("mango")
print(thisset)

Output:
{'banana', 'mango', 'apple'}

No Sidebar ads