We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Deleting Dictionary Values

You can delete existing keys using the del keyword.

names_dict = {"jack": "bronson", "jill": "mcarty", "joe": "denver"}

del names_dict["joe"]

print(names_dict)
# Prints: {'jack': 'bronson', 'jill': 'mcarty'}

Deleting Keys That Don't Exist

Notice that if you try to delete a key that doesn't exist, you'll get an error.

names_dict = {"jack": "bronson", "jill": "mcarty", "joe": "denver"}

del names_dict["unknown"]
# ERROR HERE, key doesn't exist