Skip to content

Instantly share code, notes, and snippets.

Created Jul 10, 2020
What would you like to do?
d = {'name': 'karthi',
'age': 7,
'city': 'chennai',
# If key is in dictionary means, it is removed from the dictionary.
del d['name']
print(d) # Output: {'age': 7, 'city': 'chennai'}
# If key is not in dictionary means KeyError is thrown.
del d['state']# Output:KeyError: 'state'
# clear - it will empty the dictionary.
# clear() method will return None.It will clear the original dictionary
print(d.clear()) # Output: None.
print(d) # Output: {}
# del - del keyword is used to delete the dictionary itself.
del d
# d1 is deleted and is not available.
print (d) #Output: NameError: name 'd' is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment