Python Program to Remove an item from a Dictionary

In the following example of Python program that demonstrates how to remove an item from a dictionary :
Program :
# create a dictionary
my_dict = {'apple': 2, 'banana': 3, 'orange': 4}

# print the original dictionary
print("Original Dictionary:", my_dict)

# remove an item from the dictionary
del my_dict['banana']

# print the updated dictionary
print("Updated Dictionary:", my_dict)
Output :
Original Dictionary: {'apple': 2, 'banana': 3, 'orange': 4}
Updated Dictionary: {'apple': 2, 'orange': 4}
In this example, we first create a dictionary called `my_dict` that contains three key-value pairs. We then print the original dictionary using the `print()` function.

Next, we remove the key-value pair with key 'banana' from the dictionary using the `del` keyword.

Finally, we print the updated dictionary to confirm that the item has been successfully removed.