Built-in Functions and Types

dir()

Return a sorted list of names useful for interactive inspection. Without an argument it reports names in the current local scope. With an object it consults __dir__ if present or uses its default inspection strategy. Results are not guaranteed to include every accessible attribute, especially with dynamic lookup or metaclasses. Do not treat dir as a definitive API inventory.

Formal Syntax & Structure

python syntaxpython
dir()dir(object, /)

Parameters & Attributes

NameTypeDescription
objectobjectOptional object to inspect; omit for current scope.

Return Value

list[str]

Alphabetically sorted name suggestions.

Working Example

Example Snippetpython
class Panel:    title = "Overview"    def refresh(self):        pass
print([name for name in dir(Panel()) if not name.startswith("_")])
Python Reference