set.add() in python



"add()" function is used to add the element in the set. It will add the element anywhere in the set. We can't determine the position.




Syntax:




set.add(value)







Example-1
n = {10, 20, 30, 10}

n.add(50)

print(n)


Output



{10,20,50,30}







Example-2
n = {10, 20, 30, 10}

n.add(40)

print(n)


Output



{40, 10, 20, 30}







Example-3
n = {"A", "B", "AB", "A"}

n.add("Z")

print(n)


Output



{'AB', 'B', 'A', 'Z'}