Difference between dir() and vars() in Python Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report As Python stores their instance variables in the form of dictionary belonging to the respective object both dir() and vars() functions are used to list the attributes of an instance/object of the Python class. Though having a similar utility these functions have significant individual use cases.dir() Function: This function displays more attributes than vars() function, as it is not limited to an instance. It displays the class attributes as well. It also displays the attributes of its ancestor classes.vars() Function: This function displays the attribute of an instance in the form of a dictionary.The below table provides with some significant difference between var() and dir(): vars()dir()Returns a dictionary of objects of single class where usedReturns a dictionary of objects of single class where used and its base classesIt returns a dictionary corresponding to the current local symbol table when no argument is passedIt returns the list of names in the current local scope when passed no argumentIt returns a dictionary corresponding to the object’s symbol table if a module, class or class instance object as argument (or anything else that has a __dict__ attribute) is passed.It attempt to return a list of valid attributes for that object when passed an argumentAs instances builtin types do not have __dict__ attribute, it returns an Error when used in a built-in type instance.It can be used with all built-in types without error Example 1: Python3 vars(list).keys() Output: Example 2: Python3 dir(list) Output: Comment More infoAdvertise with us Next Article Difference between dir() and vars() in Python R RajuKumar19 Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads Difference between end and sep in Python In this article we will discuss the difference between The end and sep are two parameters in Python's built-in print() function that will help to control how the output is formatted. end in PythonThe end is a parameter in Python's built-in print() function that controls what character(s) are printed 2 min read Python: Difference between dir() and help() In Python, the dir() and help() functions help programmers understand objects and their functionality.dir() lists all the attributes and methods available for an object, making it easy to explore what it can do.help() provides detailed information about an object, including descriptions of its metho 4 min read Difference between %s and %d in Python string In this article, we will see the difference between %s and %d in Python. Here, we start with the proper explanation of one at a time, then both, and at last compare these. What does %s do in Python? The % symbol is used in Python with a large variety of data types and configurations. It is used as a 3 min read Difference between List and Dictionary in Python Lists and Dictionaries in Python are inbuilt data structures that are used to store data. Lists are linear in nature whereas dictionaries stored the data in key-value pairs. In this article, we will see the difference between the two and find out the time complexities and space complexities which ar 6 min read Difference Between os.rename and shutil.move in Python When it comes to renaming or moving files and directories, two commonly used methods are os. rename and shutil. move. While both can serve the purpose of renaming and moving, they have distinct differences in terms of functionality and use cases. In this article, we will explore these differences an 3 min read Like