set.update
Add the items of other collections to the set.
Python 3.13
set.update(*others)- *others
- The collections whose items are added.Iterable
Return value
Nothing (None); the set is changed in place.
Examples
Adding items from another set
Python 3.13
s = {1, 2}
s.update({3, 4})
print(s){1, 2, 3, 4}Adding from a string and a list
Python 3.13
s = {'a'}
s.update('bc', ['d'])
print(sorted(s))['a', 'b', 'c', 'd']
Details
Unlike set.union, it changes the set itself. For sets, the |= operator does the same.
