Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

set.update

Adds members of an iterable directly to the receiving set.

Version: Python 3.14; repository image, production runtime not attested

Syntax

s.update(*others)

Adds members of an iterable directly to the receiving set.

Repeated values contribute once. The method returns None rather than the resulting set.

The method iterates through all supplied inputs and inserts their individual members into the same mutable set. Here 3 is already present and the duplicate 4 contributes a single new member. The first print displays None, the method return, while the second shows the changed contents.

s = {1}
a = s
assert s.update([1, 2], (3, 3)) is None and a == {1, 2, 3}

Examples

s = {2, 3}
print(s.update([3, 4, 4]))
print(sorted(s))

Result

None
[2, 3, 4]

The method iterates through all supplied inputs and inserts their individual members into the same mutable set. Here 3 is already present and the duplicate 4 contributes a single new member. The first print displays None, the method return, while the second shows the changed contents.

Sources