Python Function Reference

setattr
Sets the value of an attribute on an object. The counterpart to getattr().
Python 3.13
setattr(object, name, value)
object
The object.
name
The attribute's name.
value
The value to set.
Examples
Python 3.13
>>> class A: pass
>>> x = A()
>>> setattr(x, 'foo', 'bar')
<__main__.A object at 0x...>