About 860 letters

About 4 minutes

#setattr

Description: Set the value of an attribute. See also hasattr, delattr, and getattr.

def setattr(obj, name: str, value):
    '''
    Set the value of an attribute

    :param obj: An object
    :param name: The name of the attribute
    :param value: The value of the attribute
    '''

Example:

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

p = Person("Alice", 30)
setattr(p, 'name', 'Doro')
print(p.name)

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

Updated: 6/9/2025

Author: PlanC

Created: 6/9/2025