1>>> # initialise a dictionary with the keys “city”, “name”, “food”
2>>> person1_information = {'city': 'San Francisco', 'name': 'Sam', "food": "shrimps"}
3
4>>> # delete the key, value pair with the key “food”
5>>> del person1_information["food"]
6
7>>> # print the present personal1_information. Note that the key, value pair “food”: “shrimps” is not there anymore.
8>>> print(person1_information)
9{'city': 'San Francisco', 'name': 'Sam'}
1thisdict = {
2 "brand": "Ford",
3 "model": "Mustang",
4 "year": 1964
5}
6thisdict.pop("model")
1dict = {'an':30, 'example':18}
2#1 Del
3del dict['an']
4
5#2 Pop (returns the value deleted, but can also be used alone)
6#You can optionally set a default return value in case key is not found
7dict.pop('example') #deletes example and returns 18
8dict.pop('test', 'Key not found') #returns 'Key not found'