Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries

The Python delattr() function is used to delete a specified attribute from specified object.


delattr(object, attribute)


object Required. An object
attribute Required. attribute which need to deleted from object.


It raises exception if the required attribute is not found in the object. In the below example, hobby attribute is not defined in the class MyClass. Therefore, when deleting this attribute, causing an exception to occur.

class MyClass:
   name = 'John'
   age = 25
   city = 'London'

delattr(MyClass, 'city')
delattr(MyClass, 'hobby')

The output of the above code will be:

AttributeError: hobby

❮ Python Built-in Functions