Adding single items to a set with .add()
The simplest way to add one item to a set is the .add() method. You write the set name, then a dot, then add() with the item inside the parentheses.
Here is what that looks like in actual code:
my_set = {1, 2, 3} my_set.add(4) print(my_set) This prints: {1, 2, 3, 4}
The .add() method changes the set right away. You do not get back a new set — the original set gets modified. If you try to add an item that is already in the set, nothing happens. Sets do not store duplicates, so adding 2 to a set that already contains 2 leaves the set unchanged.
Key Takeaways
- Use .add() to put a single item into a set, and the set updates when ready without creating a new set.
- Use .update() when you want to add multiple items at once, whether from a list, another set, or a string.
- Sets automatically reject duplicates, so adding an item that already exists in the set has no effect.
- The .add() and .update() methods do not return anything — they modify the set in place.
Adding multiple items at once with .update()
When you need to add more than one item, use .update() instead of calling .add() over and over. The .update() method takes a collection of items — a list, another set, a tuple, or even a string — and adds all of them to your set in one step.
Here are the most common ways to use .update():
my_set = {1, 2, 3} my_set.update([4, 5, 6]) print(my_set) This prints: {1, 2, 3, 4, 5, 6}
You can also pass another set, a tuple, or even a string. If you pass a string, Python adds each character as a separate item:
my_set = {'a', 'b'} my_set.update('cd') print(my_set) This prints: {'a', 'b', 'c', 'd'}
Like .add(), the .update() method modifies the set in place. It does not return a new set, and it silently skips any items that are already in the set.
What happens when you try to add duplicates
Sets are built to store only unique items. If you add something that is already in the set, Python does nothing — no error, no warning, just no change.
my_set = {1, 2, 3} my_set.add(2) print(my_set) This still prints: {1, 2, 3}
This is actually useful. If you are not sure whether an item is already in your set, you can safely call .add() without checking first. The set handles the duplicate rejection for you. This is one reason sets are better than lists when you care about uniqueness — you do not have to write code to check before adding.
The difference between .add() and .update()
Both methods modify the set in place, but they work with different input sizes. Use .add() for a single item and .update() for multiple items. If you call .add() with a list or set, Python will treat the entire collection as one item and raise an error.
my_set = {1, 2, 3} my_set.add([4, 5]) This produces an error because lists cannot be added to sets.
With .update(), you pass the collection and Python unpacks it:
my_set = {1, 2, 3} my_set.update([4, 5]) print(my_set) This prints: {1, 2, 3, 4, 5}
Creating a new set instead of modifying the old one
Both .add() and .update() change the original set. If you want to keep the original set unchanged and create a new one with the added items, use the union operator | or the .union() method.
my_set = {1, 2, 3} new_set = my_set | {4, 5} print(my_set) print(new_set) This prints: {1, 2, 3} {1, 2, 3, 4, 5}
The original set stays the same, and you get a brand new set with both the old items and the new ones. This is useful when you need to keep the original data intact for later use.
Common mistakes when adding to sets
One frequent mistake is trying to add a list or dictionary directly to a set. Sets can only hold items that are hashable — meaning they cannot change. Lists and dictionaries can change, so they cannot go into a set.
my_set = {1, 2, 3} my_set.add([4, 5]) This produces: TypeError: unhashable type: 'list'
If you need to add multiple items, use .update() with the list instead of .add(). Another common mistake is forgetting that .add() and .update() do not return anything. If you write my_set = my_set.add(4), you will set my_set to None, not to the updated set. Always call .add() or .update() on its own line, without assigning the result.
Frequently Asked Questions
Can I add a tuple to a set?
Yes. Tuples are hashable, so they can go into a set. Use .add() for a single tuple or .update() if you have multiple tuples. If you use .update() with a tuple of tuples, Python adds each inner tuple as a separate item.
What is the difference between adding to a set and adding to a list?
Lists keep duplicates and preserve order. Sets reject duplicates and do not have a may provide order. With a list, .append() adds one item and you get a new length. With a set, .add() adds one item only if it is not already there, and the set size may not change.
Does .add() return the updated set?
No. Both .add() and .update() modify the set in place and return None. If you need a new set with the added items, use the union operator | or the .union() method instead.
Can I add None or an empty string to a set?
Yes. Both None and empty strings are hashable and can be stored in a set. They behave like any other item — if you add them twice, the set still contains only one copy.
What happens if I add items from one set to another?
Use .update() with the second set as the argument. Python unpacks the second set and adds each item to the first set. Duplicates are automatically skipped. You can also use the union operator: my_set = my_set | other_set.