This delattr()
function deletes the named attribute of an object.
delattr(object, name)
Here,
>>> class Class1:
... def __init__(self, x=0):
... self.x = x
...
>>> f = Class1(100)
>>> f.x
100
>>> delattr(f, 'x')
>>> f.x
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: Class1 instance has no attribute 'x'
Here, the named attribute x
is deleted or removed from the class Class1
.