getattr()

Built-in FunctionPython 2.0+Intermediate

Returns the value of a named attribute of an object

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
class Config:
    debug = True
    version = "1.0"

print(getattr(Config, "debug"))
print(getattr(Config, "missing", "default"))

getattr() is a built-in function that returns the value of a named attribute of an object.

Try in Playground

Tags

builtinfunctioncoreoopintrospectiondynamic

Related Items