English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The vars() function returns the __dict__ attribute of the given object.
The syntax of the vars() function is:
vars(object)
vars() accepts at most one parameter.
object-can be a module, class, instance, or any object that has a __dict__ attribute.
vars() returns the properties of the __dict__ given object.
If the object passed to vars() does not have a __dict__ attribute, it will raise a TypeError exception.
If no parameters are passed to vars(), the function acts likelocals() function.
Note: __dict__ is a dictionary or mapping object. It stores the object's (writable) properties.
class Foo: def __init__(self, a = 5, b = 10) : self.a = a self.b = b object = Foo() print(vars(object))
Output result
{'a': 5, 'b': 10}
In addition, run the following statements in the Python shell:
>>> vars(list)
>>> vars(str)
>>> vars(dict)