How to use del statement to remove a variable
Deleting with del
del
statement not only removes a
reference to an object, it also removes the name itself:
x = 1
del x
x
The code above generates the following result.
x = ["Hello", "world"]
y = x # ww w. jav a 2 s . c o m
y[1] = "Python"
print x
del x
print y
The code above generates the following result.
x
and y
referred to the same list,
but deleting x
didn't affect y
at all.
You delete the name, not the list itself.