python

Delete a key value pair from a dictionary in Python

To delete a key from a dictionary in python - del keyword can be used with the key name that you want to delete from the python dictionary.

my_car = {
  "name": "Nexon",
  "brand": "TATA",
  "color": "Green"
}

del my_car['color']

print(my_car)

In the code snippet, we are deleting a a key - color from dictionary - my_car

Was this helpful?