delattr()
Published Jul 6, 2021Updated Sep 3, 2021
Contribute to Docs
Allows the user to delete attributes from an object.
Syntax
delattr(object, name)
Parameters
object
: The object to have an attribute removed.name
: The attribute to be removed from the object.
Example 1
Use delattr()
to remove the position
attribute from the Person1
class:
class Person1:name = "Harry"age = "35"position = "Professor"employee1 = Person1()print("Employee Name: ", employee1.name)print("Employee Age: ", employee1.age)print("Employee Position: ", employee1.position)delattr(Person1, "position")print("---- UPDATE ----")print("Employee Name: ", employee1.name)print("Employee Age: ", employee1.age)# Will cause an AttributeError because attribute is removedprint("Employee Position: ", employee1.position)
All contributors
- Anonymous contributorAnonymous contributor3077 contributions
- Anonymous contributorAnonymous contributor194 contributions
- christian.dinh
- Anonymous contributor
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.