The dir()
function in Python returns a list of valid attributes and methods for the specified object. It can be used without arguments to list the names in the current scope or with an object as an argument to list the attributes and methods of that object.
Parameter Values
Parameter | Description |
---|---|
object | An optional parameter representing the object whose attributes are to be listed. If not provided, returns the list of names in the current local scope. |
Return Values
The dir()
function returns a list of attribute names (strings) of the object.
How to Use dir()
in Python
The dir()
function returns the list of names in the current local scope or in the specified object's scope.
dir()
The dir()
function can also be used on modules to list all functions and attributes available in that module.
dir(math)
You can also use the dir()
function on objects to see all the methods and attributes of that object.
dir(list)