Home >>Python Built-in Functions >Python delattr() Function
Python delattr() function is used to delete the required attribute from the given input object. It takes two parameter that is the name of the object and the name of the attribute to be deleted.
Syntax:delattr(object, attribute)
Parameter | Description |
---|---|
object | This is a required parameter. It defines the given object. |
attribute | This is a required parameter. It defines the name of the attribute you want to remove. |
Example
class Person: name = "Jerry" age = 21 country = "India" state = "Delhi" data = Person() print('Before deleting the attribute--') print('Name =', data.name) print('Age =', data.age) print('Country =', data.country) print('State =', data.state) delattr(Person, 'state') print('After deleting the attribute--') print('Name =', data.name) print('Age =', data.age) print('Country =', data.country) print('State =', data.state)