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?
Similar Posts
- Get Key from a Dictionary using Value in Python
- Remove a key from a dictionary Python
- Check if a key exist in a dictionary Python
- Sort a dictionary by value in Python
- Check if a value exists in a dictionary Python
- Get all values by key name from a list of dictionaries Python
- Django send post request with different field than primary key.