In this tutorial we will learn about the python delattr() method and its uses.
The delattr() method will delete the specific attribute from the particular object if that particular object allows it.
The syntax of delattr() method is:
Python delattr() Method Parameters
The delattr() takes two parameters as an argument:
object – The name of the object from which attribute is to remove.
name – a string in which can be the name of the attribute to be removed from the object.
Let see some examples of the delattr() method.
Example 1: How does delattr() work?
The output will be as follow:
Here, attribute z is removed from the Coordinate class using delattr(Coordinate, ‘z’).
Example 2: Deleting Attribute using del Operator.
We can also delete attributes of an object using the del operator.
This will show the same output as example 1.
Rules of python delattr() Parameters
delattr() does not return any value; it only removes an attribute. Default it will return None as an output.