Remove Dictionary Item using pop() :
thisdict.pop("model")
print(thisdict)
Output :
{'brand': 'Ford', 'year': 2020, 'color': 'red', 'engine': 'V8'}
Remove Last Inserted Item using popitem() :
thisdict.popitem()
print(thisdict)
Output :
{'brand': 'Ford', 'year': 2020, 'color': 'red'}
Delete Entire Dictionary using del :
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
del thisdict
Output :
Dictionary deleted successfully (no output if print is skipped)
Clear Dictionary using clear() :
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.clear()
print(thisdict)
Output :
{}