Python Add Set Items
Add Set Items
To add one item to a set use the add()
method.
To add more than one item to a set use the update()
method.
Example
Add an item to a set, using the add()
method:
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset)
Try it Yourself »
Example
Add multiple items to a set, using the update()
method:
thisset = {"apple", "banana", "cherry"}
thisset.update(["orange",
"mango", "grapes"])
print(thisset)
Try it Yourself »