How to delete specific attribute from object in Python

1 Answer

0 votes
class Worker:
    name = "Fox"
    age = 52
    profession = "Programmer"

o = Worker()

print(o.name)
print(o.age)
print(o.profession)

delattr(Worker, 'age')

print(o.name)
print(o.profession)
# print(o.age)  # 'Worker' object has no attribute 'age'


'''
run:

Fox
52
Programmer
Fox
Programmer

'''

 



answered Dec 8, 2018 by avibootz

Related questions

...