On this page
  1. setattr
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

setattr

Prev: set | Up: __builtins__ | Next: slice
Rel: callable, delattr, dir, getattr, hasattr
Ref: docs.python.org — setattr
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import setattr

Overview & Signature

setattr(obj, name, value, /)

Sets the named attribute on the given object to the specified value.

Usage

class Cfg: pass
c = Cfg()
setattr(c, "host", "localhost")
assert c.host == "localhost"

Gotchas

REPL Inspect

help(setattr)

Linked from

Related notes