Delete a set using del keyword Dry Run in PYTHON

Delete a set using del keyword is an interactive PYTHON dry run visualizer from the Sets 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 a set using del keyword Program Code

# Delete an entire set using del keyword
my_set = {10, 20, 30, 40, 50}
print("Set before deletion:", my_set)

# Delete the set
del my_set

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

# Deleting a non-existent set causes error
try:
    del non_existent_set
except NameError as e:
    print(f"Cannot delete: {e}")

# Alternative: reassign to None (not the same as delete)
another_set = {1, 2, 3}
another_set = None
print(f"\nReassigned to None: {another_set}")
print("Note: Set still exists in memory but variable points to None")

View the complete Sets programs page.

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