Python dir() Function
Description
dir() When called without parameters, the function returns a list of variables, methods, and defined types in the current scope; with parameters, it returns a list of the parameter's attributes and methods. If the parameter contains the method __dir__(), that method will be called. If the parameter does not contain __dir__(), the method will collect parameter information to the greatest extent possible.
Syntax
dir Syntax:
dir([object])
Parameter Description:
- object -- an object, variable, or type.
Return Value
Returns a list of the module's attributes.
Example
The following examples show the use of dir:
dir
(
)
Get the list of attributes of the current module
[
'
builtins
'
,
'
doc
'
,
'
name
'
,
'
package
'
,
'
arr
'
,
'
myslice
'
]
dir
(
[
]
)
View the methods of a list
[
'
add
'
,
'
class
'
,
'
contains
'
,
'
delattr
'
,
'
delitem
'
,
'
delslice
'
,
'
doc
'
,
'
eq
'
,
'
format
'
,
'
ge
'
,
'
getattribute
'
,
'
getitem
'
,
'
getslice
'
,
'
gt
'
,
'
hash
'
,
'
iadd
'
,
'
imul
'
,
'
init
'
,
'
iter
'
,
'
le
'
,
'
len
'
,
'
lt
'
,
'
mul
'
,
'
ne
'
,
'
new
'
,
'
reduce
'
,
'
reduce_ex
'
,
'
repr
'
,
'
reversed
'
,
'
rmul
'
,
'
setattr
'
,
'
setitem
'
,
'
setslice
'
,
'
sizeof
'
,
'
str
'
,
'
subclasshook
'
,
'
append
'
,
'
count
'
,
'
extend
'
,
'
index
'
,
'
insert
'
,
'
pop
'
,
'
remove
'
,
'
reverse
'
,
'
sort
'
]
Python built-in function