How to create data attributes of a class in run-time in python?
The setattr used to sets the named attribute on the given object with a specified value.
class Employee: pass emp1 = Employee() setattr(emp1, 'Salary', 12000) emp2 = Employee() setattr(emp2, 'Age', 25) print(emp1.Salary) print(emp2.Age)
Sample output of above program.
12000 25
2019-06-23T12:50:32+05:30
2019-06-23T12:50:32+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution