How to Delete List Completely in Python


In this example we will show how to delete the list completely using the del keyword in Python.

Source Code

my_list = ['a', 'b', 'c', 'd', 'e']
del my_list
print(my_list)   # this will thrown an error because you have succsesfully deleted "my_list"

Output:

Traceback (most recent call last):
  File "demo.py", line 3, in 
    print(my_list)   # this will thrown an error because you have succsesfully deleted "my_list"
NameError: name 'my_list' is not defined
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments