How do I delete data in a variable without deleting the variable?

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

Answers (1)

Brendan Abel
Brendan Abel

Reputation: 37509

Just do

price = None

Anything referenced by that variable will get garbage-collected.

Upvotes: 4

Related Questions