Delete dictionary using del keyword Dry Run in PYTHON

Delete dictionary using del keyword is an interactive PYTHON dry run visualizer from the Dict programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Delete dictionary using del keyword Program Code

# Delete entire dictionary using del
my_dict = {"a": 1, "b": 2, "c": 3}
print("Before deletion:", my_dict)

# Delete the entire dictionary
del my_dict

# Trying to access after deletion causes error
try:
    print(my_dict)
except NameError as e:
    print(f"\nError after deletion: {e}")

# Delete specific key from dictionary
another_dict = {"x": 10, "y": 20, "z": 30}
print(f"\nBefore deleting key: {another_dict}")

del another_dict["y"]
print(f"After deleting key 'y': {another_dict}")

# Delete non-existent key raises KeyError
try:
    del another_dict["w"]
except KeyError as e:
    print(f"Error: Key {e} not found")

View the complete Dict programs page.

Program Console Delete dictionary using del keyword Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.