Python del Keyword
ExampleGet your own Python Server
Delete an object:
class MyClass:
name = "John"
del MyClass
print(MyClass)
Try it Yourself »
Definition and Usage
The del
keyword is used to delete objects.
In Python everything is an object, so the del
keyword can also be used to delete variables, lists, or parts of a list etc.
More Examples
Example
Delete the first item in a list:
x =
["apple", "banana", "cherry"]
del x[0]
print(x)
Try it Yourself »