Python setattr() function
Published February 16, 2022Among the typical activities in programming is assigning values to variables. You can achieve this by using object and constructor functions. The setattr() method offers an alternative way to assign values to variables.
Python's setattr() function is used to assign attributes to object values.
Syntax
setattr(object, var, value) |
where:
object: the object to be assigned the attribute
var: the attribute to be assigned to the object
value: the value assigned to the variable
Example
class ILP: |
Output
Before setattr variable name : ILovePython |
Article Contributed By :
|
|
|
|
225 Views |