Google News
logo
Python Program to Empty a Dictionary
In the following example of Python program to empty a dictionary :
Program :
my_dict = {'a': 1, 'b': 2, 'c': 3}
print("Original dictionary:", my_dict)

my_dict.clear()
print("Dictionary after clearing:", my_dict)
Output :
Original dictionary: {'a': 1, 'b': 2, 'c': 3}
Dictionary after clearing: {}
In the above program, we first create a dictionary `my_dict` with some key-value pairs. Then we print the original dictionary using the `print()` function.

Next, we use the `clear()` method to remove all key-value pairs from the dictionary. Finally, we print the dictionary after clearing using the `print()` function.