How to Delete Dictionary Completely in Python


In this example, we will learn how to delete the dictionary completely using the del keyword in Python.

Source Code

mydict = {
  'name': 'Steven',
  'age': 24,
  'ID': 123456
}

del mydict
print(mydict)

Output:

Traceback (most recent call last):
  File "demo.py", line 8, in 
    print(mydict)
NameError: name 'mydict' is not defined
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments