Python dir() function
Published February 15, 2022In Python, dir() is a powerful inbuilt function that is used to return the lists of methods and attributes of any object in a program including, dictionaries, lists, strings, modules, functions, etc. when this function is called, and it returns the list of attributes of the selected object.
Syntax
The syntax of the dir() function includes:
Dir({object}), |
where an object can be either a dictionary, string, list, module, etc.
Example
In this example, we are going to display the list of the random library content using the dir() function
import random print("The random library content includes::") print(dir(random)) |
Output
Article Contributed By :
|
|
|
|
238 Views |