Deleting a list in Python can be done by using the del
statement or assigning an empty list to the variable. Here are two examples:
Example 1:
my_list = [1, 2, 3, 4, 5] del my_list print(my_list)
Output:
NameError: name ‘my_list’ is not defined
Example 2:
my_list = [1, 2, 3, 4, 5] my_list = [] print(my_list)
Output:
[]