setattr()

Built-in FunctionPython 2.0+Intermediate

Sets the value of a named attribute on an object

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
class Config:
    pass

setattr(Config, "debug", True)
setattr(Config, "version", "2.0")
print(Config.debug, Config.version)

setattr() is a built-in function that sets the value of a named attribute on an object.

Try in Playground

Tags

builtinfunctioncoreoopintrospectiondynamic

Related Items