Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python – Deletes Object Attribute – delattr() Function with Examples

delattr() function is used to delete attributes from the object in Python programming language. delattr() does not return any value and it deletes attribute if object allows it.

delattr() function is a part of Python Built-in Functions.

 

Syntax of delattr() Function

The syntax of delattr() function in Python is:

 

Parameters of delattr() Function in Python

delattr() function takes two parameters.
object – Where object is the object from which attribute name is going to remove.
name – Where name is the name of attribute which is going to remove. name is in the string form.

 

Compatibility

delattr() function is available and compatible with both Python 2.x and 3.x.

 

Return Value of delattr() Function in Python

delattr() function returns nothing, besides it only removes attributes from the object when object allow attribute removal.

 

Python delattr() Function Example 1


Output:
a = 45
Traceback (most recent call last):
b = -33
c = 0
--By deleting c attribute--
b = 45
print('c = ',myPoint.c)
b = -33
AttributeError: 'MyCoordinate' object has no attribute 'c'

 

Python delattr() Function Example 2


Output:
a = 45
Traceback (most recent call last):
b = -33
c = 0
--By deleting c attribute--
b = 45
print('c = ',myPoint.c)
b = -33
AttributeError: 'MyCoordinate' object has no attribute 'c'

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved