Javatpoint Logo
Javatpoint Logo

Python vars() Function

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

Signature

Parameters

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

Return

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

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.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA