Allows the user to delete attributes from an object.
object: The object to have an attribute removed.
name: The attribute to be removed from the object.
delattr() to remove the
position attribute from the
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)
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
- Anonymous contributors
Learn Python on Codecademy
- Anonymous contributorsAnonymous contributors