Home >>Python Keywords >Python del Keyword

Python del Keyword

Python del Keyword

Python del keyword is used to delete the objects present in the program. This del keyword can also be used to delete the variables, lists, or parts of a list, etc.

Here is an example of Python del keyword:

class MyClass:
name = "Jerry"
del MyClass
print(MyClass)

Output:
Traceback (most recent call last):
File "./prog.py", line 6, in NameError: name 'MyClass' is not defined
Example 2:

x = "Jerry"
del x
print(x)

Output:
Traceback (most recent call last):
File "demo.py", line 5, in print(x)
NameError: name 'x' is not defined