Python vars() Function
Description
vars()The function returns a dictionary object of the object's attributes and attribute values.
Syntax
vars() function syntax:
vars([object])
Parameters
- object -- the object
Return Value
Returns a dictionary object of the object's attributes and attribute values. If no argument is given, it prints the attributes and attribute values at the current call location, similar to locals().
Examples
The following example demonstrates how to use vars():
>>>print(vars())
{'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', '__doc__': None, '__package__': None}
>>> class Example:
... a = 1
...
>>> print(vars(Example))
{'a': 1, '__module__': '__main__', '__doc__': None}
>>> example = Example()
>>> print(vars(example))
{}
Python Built-in Functions