?
What is the purpose of the built-in function dir()?
Answer & Solution
Correct Answer:
Option
A
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:
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__', ...]
Join the Discussion
Login to post a comment or share your explanation.
Login