Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

dict.update

Copies key and value bindings into the current dictionary.

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

Syntax

m.update([other], **kwargs)

Copies key and value bindings into the current dictionary.

An incoming duplicate key replaces the old value. The method returns None.

Copies bindings from a mapping, iterable of pairs or keyword arguments into the receiver. The example overwrites a with seven and inserts b with nine. Since the mutation returns None, printing the call and printing the resulting mapping give different outputs.

d = {"a": 0}
assert d.update([("a", 1)], a=2) is None and d == {"a": 2}

Examples

m = {"a": 3}
print(m.update(a=7, b=9))
print(m)

Result

None
{'a': 7, 'b': 9}

Copies bindings from a mapping, iterable of pairs or keyword arguments into the receiver. The example overwrites a with seven and inserts b with nine. Since the mutation returns None, printing the call and printing the resulting mapping give different outputs.

Sources