Vidyalelo
Python · Q9

Python Built

Programming · Python · question 9

Q9

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

A.
Returns a list of attributes and methods of an object
Answer
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

Answer: Option A
Solution:
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__', ...]