Situatie
The setattr() function sets the value of the attribute of an object.
Solutie
Pasi de urmat
class Person:
name = ‘Adam’
p = Person()
print(‘Before modification:’, p.name)
# setting name to ‘John’
setattr(p, ‘name’, ‘John’)
print(‘After modification:’, p.name)
Output:
Before modification: Adam
After modification: John
Leave A Comment?