Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

dict.clear

Removes all dictionary entries in place.

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

Syntax

m.clear()

Removes all dictionary entries in place.

A reference to the same dictionary observes the change. Clearing returns None.

Clearing removes every key and value from the original dictionary. The first print displays None, the method result; the alias then prints the now-empty dictionary, proving the receiver was changed rather than replaced.

d = {"x": 1}
view = d.keys()
assert d.clear() is None and len(view) == 0

Examples

m = {"a": 3}
alias = m
print(m.clear())
print(alias)

Result

None
{}

Clearing removes every key and value from the original dictionary. The first print displays None, the method result; the alias then prints the now-empty dictionary, proving the receiver was changed rather than replaced.

Sources