Dict Methods

dict.clear()

Empties the existing dictionary, retaining its identity. All aliases and existing views reflect the empty mapping. It does not recursively clear objects formerly stored as values. Calling clear on an empty dictionary is valid. Assigning a fresh dictionary to a variable instead leaves other references to the original dictionary untouched.

Formal Syntax & Structure

python syntaxpython
mapping.clear()

Return Value

None

No new dictionary is returned.

Working Example

Example Snippetpython
stock = {"pen": 4, "book": 2}alias = stockview = stock.keys()print(stock.clear())print(alias, list(view))
Python Reference