ID EN
Built-in Functions

dir

Python 3.11 🇮🇩 Bahasa Indonesia

Tanpa argumen, kembalikan daftar nama dalam lingkup lokal saat ini. Dengan argumen, cobalah mengembalikan daftar atribut yang valid untuk objek tersebut.

Syntax

PYTHON
dir()

Contoh

Example 1
PYTHON
>>> import struct
>>> dir()    show the names in the module namespace
['__builtins__', '__name__', 'struct']
>>> dir(struct)    show the names in the struct module
['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__',
 '__initializing__', '__loader__', '__name__', '__package__',
 '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
 'unpack', 'unpack_from']
>>> class Shape:
...     def __dir__(self):
...         return ['area', 'perimeter', 'location']
>>> s = Shape()
>>> dir(s)
['area', 'location', 'perimeter']

See Also

__dir__() __getattr__() __getattribute__() dir() __dir__() __dict__ __getattr__() dir()