Javatpoint Logo
Javatpoint Logo

Python vars() Function

Python vars() function returns the __dict__ attribute of the given object.



object (optional): It is an object and can be a module, class, instance, or any other object having __dict__ attribute.


It returns the __dict__ attribute of the given object. If any object fails to match the attribute, it raises a TypeError exception.

Python vars() Function Example 1

The below example shows the working of vars().


{'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.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA