Function Details: setattr

Description


Sets a named attribute on an object with the given value.


Extended Description


The setattr() function sets the value of the named attribute of an object. It's the counterpart to getattr(). If the object allows it, setattr() sets the named attribute to the given value. This is equivalent to object.name = value. If the object doesn't allow setting the attribute, it raises an AttributeError.


Read More about setattr from Python Documentation

Function Signature


setattr(object: Any, name: str, value: Any) -> None

Module: builtins

Parameters



Parameter List


  • object: Any
  • name: str
  • value: Any

Return


This function doesn't return a value (None).


Return Type


None

Output

Explanation

This example shows how to use setattr() to add attributes to an object dynamically.