xxxxxxxxxx
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.pop("model")
xxxxxxxxxx
my_dict = {31: 'a', 21: 'b', 14: 'c'}
del my_dict[31]
print(my_dict)
xxxxxxxxxx
# define a dictionary
my_dict = {'a': 1, 'b': 2, 'c': 3}
# remove a key-value pair from the dictionary
value = my_dict.pop('b')
print(value) #print as 2
print(my_dict) #print as {'a': 1, 'c': 3}
# remove a key-value pair from the dictionary with a default value
value = my_dict.pop('d', None)
print(value) #print as None
print(my_dict) #print as {'a': 1, 'c': 3}
# remove a key-value pair from the dictionary using the `del` statement
del my_dict['a']
print(my_dict) #print as {'c': 3}
xxxxxxxxxx
hh = {"a":3, "b":4, "c":5}
# delete a entry
del hh["b"]
print(hh)
# {'a': 3, 'c': 5}