Python vars() Function
Python vars() Function
The vars() function in Python returns the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute.
Syntax
vars([object])
Parameter
object: This parameter represents any object with a __dict__attribute
Return
This function returns the __dict__ attribute.
Example 1
# Python program explaining # the vars() function class Record: def __init__(record, name = "Reema", marks= 96, name2 = "Rahul"): record.name = name record.marks = marks record.name2 = name2 val = Record() print(vars(val))
Output
{'name2': 'Rahul', 'marks': 96, 'name': 'Reema'}