Python Dir Exercises

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))

Need More Exercises?

Check out Holy Python AI+ for amazing Python learning tools.

*Includes 14 more programming languages, inspirational tools and 1-on-1 consulting options.
Umut Sagir
Finance & Data Science Professional,
Founder of HolyPython