Python del Keyword

Example

Delete object:

class MyClass:
  name = "John"
del myClass
print(myClass)

Run Instance

Definition and Usage

del is used to delete objects. In Python, everything is an object, so the del keyword can be used to delete variables, lists, or list slices, etc.

More Examples

Example

Delete variable:

x = "hello"
del x
print(x)

Run Instance

Example

Delete the first item in the list:

x = ["apple", "banana", "cherry"]
del x[0]
print(x)

Run Instance