Python 3 reference · Set Methods
Python Set update() Method
Add all elements from one or more iterables to the set, in place. The same as a |= b.
Python 3 Since 3.0
Syntax
set.update(*others)
Parameters
| Parameter | Description |
|---|---|
*others |
One or more iterables. |
Return value
None.
Examples
s = {1}
s.update([2, 3], {4})
print(s)
Output
{1, 2, 3, 4}letters = set()
letters.update("hello") # a string adds its characters
print(sorted(letters))
Output
['e', 'h', 'l', 'o']
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
set.add()· Add one element to the set. Adding an element that is already present does nothing.set.union()· Return a new set with all elements from this set and the others. The same as a | b.- Python Sets · tutorial