Reputation: 25
I'm trying to make a program which you can add stuff to your shopping list.
shopping_list = ["Eggs", "Milk", "Bread"]
Now i know how to add and remove items, but how do i delete the string or number in a variable without losing the variable?
price = "£12"
If I do del price
I destroy the variable.
If I try print price
i get an error:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
print price
NameError: name 'price' is not defined
Upvotes: 1
Views: 85
Reputation: 37509
Just do
price = None
Anything referenced by that variable will get garbage-collected.
Upvotes: 4