Python Forum

Full Version: Question on dir() function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the following code which uses dir() function.

Want to know why dir() function is used here.
[Image: Python-dir-Example-dir-Function-In-Python-Tutorial.png]


Question source: https://www.adaface.com/blog/python-inte...questions/
Please post code, not sceeen-shots.

No idea. It does not do anything that has a lasting effect. The information in not used in any way, other than printing. My guess is dir() is being used for demonstrating what dir() does; return attribute names for the object. Maybe you are supposed to carefully scan the printed information and see that "name", "age" and "country" are attributes of "Child", but things added to dictionaries or tuples do not become attributes.

It is a dumb demonstration.