Examveda
Examveda

What is the purpose of the built-in function dir()?

A. Returns a list of attributes and methods of an object

B. Converts a string to lowercase

C. Returns the square of a number

D. Returns the absolute value of a number

Answer: Option A

Solution(By Examveda Team)

The correct answer is Option A: Returns a list of attributes and methods of an object.
The dir() function in Python is used to return a list of attributes and methods of an object.
When called without an argument, it returns the list of names in the current local scope.
For example:
my_list = [1, 2, 3]
print(dir(my_list))  # Output: ['__add__', '__class__', '__contains__', ...]

This Question Belongs to Python Program >> Python Built In Functions

Join The Discussion

Related Questions on Python Built In Functions