Removing a Specific Element from a Dictionary
When deleting data from a dictionary, you can choose the item to delete using the Key
.
To delete a specific key-value pair, use the del
keyword and specify the key to be deleted within the square bracket ([]).
Removing a Value from a Dictionary
order = { "product_id": 2, "product_name": "Computer", "quantity": 3, "price": 1000 } # Remove the "quantity" key and its value del order["quantity"]
Mission
0 / 1
Use the del
keyword to remove a specific key-value pair from a dictionary.
True
False
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result