Python vars() FunctionLast Updated : 17 Mar 2025 In Python, the vars() function is commonly used to return the __dict__ attribute of the given object. Python vars() Function SyntaxIt has the following syntax: Parameters
ReturnIt returns the __dict__ attribute of the given object. If any object fails to match the attribute, it raises a TypeError exception. Python vars() Function ExampleThe below example shows the working of the vars() function in Python. Output:
{'y': 9, 'x': 7}
Explanation: In the above example, we define a class named as Python and made InstanceOfPython of Python class and in return, it prints the __dict__ attribute of the x and y object. Next TopicPython Built in Functions |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India