W3docs

Delete an element from a dictionary

To delete an element from a dictionary in Python, you can use the del statement.

To delete an element from a dictionary in Python, you can use the del statement. For example:

Delete an element from a dictionary in Python using del keyword

python— editable, runs on the server

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Python - The Practical Guide</div>

You can also use the pop() method to delete an item from a dictionary and return its value. For example:

Delete an element from a dictionary in Python using pop method

python— editable, runs on the server

You can also use the pop() method with a default value, in case the key is not found in the dictionary. For example:

Delete an element from a dictionary in Python using pop method with a default value

python— editable, runs on the server