The Python docs say all that needs to be said, as far as I can see.

setattr(object, name, value)

This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value. The string may name an existing attribute or a new attribute. The function assigns the value to the attribute, provided the object allows it. For example, setattr(x, 'foobar', 123) is equivalent to x.foobar = 123.

Answer from Chris Morgan on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_setattr.asp
Python setattr() Function
class Person: name = "John" age = 36 country = "Norway" setattr(Person, 'age', 40) Try it Yourself ยป
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ setattr
Python setattr() | Programiz
August 21, 2024 - # setting name to 'John' setattr(p, 'name', 'John') print('After modification:', p.name)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-setattr-method
Python setattr() method - GeeksforGeeks
July 11, 2025 - ... class Person: def __init__(self): pass p = Person() setattr(p, 'name', 'kiran') print(f"name: {p.name}") ... In the given example, we have defined a animal class with a class variable name and we are showing how can we set the value of the ...
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ python built-in functions โ€บ python setattr
Python setattr() - Set a Value to an Attribute of an Object
October 2, 2022 - Note that the setattr() only changes an individual person object, not the Person class. If you create another instance of the Person class, this object wonโ€™t have the age attribute. For example:
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_setattr_function.htm
Python setattr() Function
The Python setattr() function returns None value. Practice the following examples to understand the use of setattr() function in Python:
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ python-setattr
Python's setattr function and __setattr__ method - Python Morsels
June 9, 2022 - For example the variable attribute might contain the string "color" (representing the color attribute we're meant to assign to): ... We need some way to dynamically assign an attribute!
Find elsewhere
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ functions โ€บ setattr.html
setattr โ€” Python Reference (The Right Way) 0.1 documentation
f = Foo() print dir(f) #[โ€˜__doc__โ€™, โ€˜__module__โ€™] setattr(Foo, โ€˜barโ€™, b) print dir(f) #[โ€˜__doc__โ€™, โ€˜__module__โ€™, โ€˜barโ€™] f.bar() #bar
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ python-setattr-function
Python setattr() Function - AskPython
December 30, 2019 - This example constructs objects and sets the attributes of each subject to their corresponding marks, for a single student. After constructing the Student object using setattr(), we use getattr() and sort the subject-wise marks of students.
๐ŸŒ
ZetCode
zetcode.com โ€บ python โ€บ setattr-builtin
Python setattr Function - Complete Guide
This example shows setattr working with custom classes and some built-in mutable types. However, immutable types like integers don't support dynamic attribute assignment. The error demonstrates that Python prevents modifying built-in types that weren't designed for dynamic attribute assignment.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ built-in โ€บ setattr()
Python setattr() - Set Attribute Value | Vultr Docs
September 27, 2024 - The code modifies the name attribute of the person instance to 'John Doe'. Initially, the attribute is set to 'Jane Doe', and then setattr() reassigns it.
๐ŸŒ
Toppr
toppr.com โ€บ guides โ€บ python-guide โ€บ references โ€บ methods-and-functions โ€บ python-setattr
Python setattr() Function: What is setattr in Python used for?
November 10, 2021 - ... # Python program to illustrate setattr() function class Details: name = 'Sam' age = 24 # Create an object of the class d = Details() print('Name before modification:', d.name) print('Age before modification:', d.age) setattr(d, 'name', 'Timmy') ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ python-setattr
Python setattr() โ€“ Be on the Right Side of Change
Create a Car object porsche with a new attribute speed and set it to the value 100: # Define class with one attribute class Car: None # Create object porsche = Car() setattr(porsche, 'speed', 100) # What's the value for attribute speed? print(porsche.speed) # 100 ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-set-and-delete-object-attributes-using-setattr-and-delattr-417952
How to set and delete object attributes using setattr() and delattr() | LabEx
Understanding how to effectively manage object attributes is a fundamental skill for any Python programmer. The setattr() function in Python is used to set the value of an object's attribute dynamically.
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ python โ€บ python-setattr
Python setattr() Builtin Function - Examples
April 3, 2023 - Python setattr() builtin function is used to set an attribute with a value for given object. If the attribute already exists, then the value is updated with the new value. If the attribute is not present, new attribute for the object is created, if the object allows.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ python-setattr-function
Python setattr() function with Examples - Javatpoint
Python setattr() function with Examples on append(), clear(), extend(), insert(), pop(), remove(), index(), count(), pop(), reverse(), sort(), copy(), all(), bool(), enumerate(), iter(), map(), min(), max(), sum() etc.
๐ŸŒ
Tutorial Reference
tutorialreference.com โ€บ python โ€บ reference โ€บ methods โ€บ built-in โ€บ python-setattr-function
Python setattr() Function | Tutorial Reference
setattr() function can be used to modify an existing attribute of an object. In the following example, the Person instance p has a name attribute set to 'Tom'. setattr() function is then used to change the name attribute to 'Ryan'.