del Statement

The del statement removes a single reference to an object, and its syntax is:
del obj1[, obj2[, … objN… ]]
For example, executing del foo2 in the example above has two results:
(1) removes name foo2 from namespace
(2) lowers reference count to object ‘foobar’ (by one)
Further still, executing del foo1 will remove the final reference to the ‘foobar’ object,
decrementing the reference counter to zero and causing the object to become “inaccessible” or “unreachable.” It is at this point that the object becomes a candidate for garbage collection. Note that any tracing or debugging facility may keep additional references to an object, delaying or postponing that object from being garbage-collected. Consider the following example :


>>> a = 1
>>> a
>>> del(a)
>>> a

Traceback (most recent call last):
  File "<pyshell#105>", line 1, in <module>
NameError: name 'a' is not defined

You may also like...