-
-
Save IndhumathyChelliah/f742ebf86aa63622b74c27d20ca98ca5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
d.clear() | |
# 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