how to delete a key and value to a dictionary code example
Example 1: python delete key from dict
del dictionary['key']
Example 2: python remove a key from a dictionary
del dictionary['key']
dictionary = {'a': 3, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
del dictionary['c']
dictionary
--> {'a': 3, 'b': 2, 'd': 4, 'e': 5}
Example 3: python delete value from dictionary
dict.pop('key')
dict.pop('key', 'key not found')
Example 4: python delete value from dictionary
dict = {'an':30, 'example':18}
del dict['an']
dict.pop('example')
dict.pop('test', 'Key not found')