Let’s check out some exercises that will help you understand Python’s dir() function better.

Exercise 5-a

Take a look at the attributes and methods of the str class.


dir() will show attributes and methods of an object.

print(dir(str))

 

Exercise 5-b

Now print the attributes and methods of a list.


dir() will show attributes and methods of an object.

print(dir(lst))

Exercise 5-c

Can you print the attributes and methods of a dictionary?.


dir() will show attributes and methods of an object.

print(dir(lst))