Product SiteDocumentation Site

11.6. Deleting an object

As we already know how to create an object , now we are going to see how to delete an python object. We use del for this.

>>> s = "I love you"
>>> del s
>>> s
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 's' is not defined

del actually decreases reference count by one. When the reference count of an object becomes zero the garbage collector will delete that object.