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

ParameterDescription
*others One or more iterables.

Return value

None.

Examples

Add many elementsTry it yourself
s = {1}
s.update([2, 3], {4})
print(s)

Output

{1, 2, 3, 4}
Strings add charactersTry it yourself
letters = set()
letters.update("hello")   # a string adds its characters
print(sorted(letters))

Output

['e', 'h', 'l', 'o']

Version history

VersionChange
Python 3.0Added