Python Program to Delete an Element From a Dictionary

 

Example 1: Using del keyword

my_dict = {31: 'a', 21: 'b', 14: 'c'}

del my_dict[31]

print(my_dict)

Example 2: Using pop()

my_dict = {31: 'a', 21: 'b', 14: 'c'}

print(my_dict.pop(31))

print(my_dict)

0 Comments