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
1 2 3 |
vars([object]) |
Parameter
object: This parameter represents any object with a __dict__attribute
Return
This function returns the __dict__ attribute.
Example 1
1 2 3 4 5 6 7 8 9 10 11 |
# 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
1 2 3 |
{'name2': 'Rahul', 'marks': 96, 'name': 'Reema'} |