Python Dictionary clear() Method
Removes all elements from the dictionary.
Syntax
Python
Copy Code
dictionary.clear()
Example
Python
Copy Code
products = { 'toothbrush': 2.50, 'tomato soup': 1.99 } print(f'Number of products: {len(products)}') products.clear() print(f'Number of products after clear: {len(products)}')
Output
Number of products: 2 Number of products after clear: 0