dir()
Built-in FunctionPython 2.0+Intermediate
Lists the names (attributes and methods) of an object or current scope
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
print(dir(int)[:5]) print(dir(str)[:5])
dir() is a built-in function that lists the names (attributes and methods) of an object or current scope.
Try in PlaygroundTags
builtinfunctioncoreintrospection
Related Items
vars()
Built-in Function
Returns the __dict__ attribute of an object
type()
Built-in Function
Returns the type of an object, or creates a new type dynamically
inspect
Stdlib — Introspection
Inspect live objects: source code, signatures, class hierarchies
hasattr()
Built-in Function
Returns True if an object has the given named attribute
getattr()
Built-in Function
Returns the value of a named attribute of an object