vars()
Built-in FunctionPython 2.0+Intermediate
Returns the __dict__ attribute of an object
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
class Point: def __init__(self, x, y): self.x = x self.y = y p = Point(1, 2) print(vars(p))
vars() is a built-in function that returns the __dict__ attribute of an object.
Try in PlaygroundTags
builtinfunctioncoreintrospectionoop
Related Items
dir()
Built-in Function
Lists the names (attributes and methods) of an object or current scope
globals()
Built-in Function
Returns a dictionary of the current global symbol table
locals()
Built-in Function
Returns a dictionary of the current local symbol table
__dict__
Dunder Attribute
Dictionary holding an object's writable attributes
getattr()
Built-in Function
Returns the value of a named attribute of an object