dict.clear()
dict.clear() is a Python method in the Dictionary Methods category. Removes all items from the dictionary. The syntax is dict.clear(). Returns: None. A typical example: d = {"a": 1}
d.clear()
# d = {}. A close sibling is dict.get(), which returns the value for key if it exists, otherwise returns default. A close sibling is dict.keys(), which returns a view object of all keys in the dictionary. A close sibling is dict.values(), which returns a view object of all values in the dictionary. A close sibling is dict.items(), which returns a view object of all (key, value) pairs as tuples. More about this category: Dictionary methods for key-value operations — get, keys, items, update, and more. For a broader walkthrough, read the Dictionary Methods guide. Related Dictionary Methods entries: dict.get(), dict.keys(), dict.values(), dict.items(), dict.update(), dict.pop(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.