Sunday, November 8, 2020

, ,

Example Program for delattr() function in python

Python delattr() function used to delete an attribute from an object.

Syntax For delattr :-

delattr(object, name)

delattr () Parameters in Pyhton

There two attribute which is used in Delattr () function in python:-

  • First one is object where name attribute is removed from that object

  • second one is name it can be string which is removed from the object.

  • delattr() function in python doesn't return any value.

Python getattr Example Program in python:-

class Coordinate:
  x = 10
  y = -5
  z = 0

point1 = Coordinate() 

print('x = ',point1.x)
print('y = ',point1.y)
print('z = ',point1.z)

delattr(Coordinate, 'z')

print('--After deleting z attribute--')
print('x = ',point1.x)
print('y = ',point1.y)

# Raises Error
print('z = ',point1.z)

OUTPUT : -

Program For delattr() function in python
Program For delattr() function


0 comments:

Post a Comment