dir()Expert Examples

Lists the names (attributes and methods) of an object or current scope

dir() performance and internals

Performance characteristics and CPython implementation details.

python
# dir() internals
import dis

def using_dir():
    pass

# Bytecode analysis
dis.dis(using_dir)

# Check if it's truly built-in
import builtins
print(f"\ndir is builtin: {hasattr(builtins, 'dir')}")
print(f"Type: {type(builtins.dir)}")

Understanding the internal implementation helps optimize hot paths in performance-critical code.

Want to try these examples interactively?

Open Expert Playground