vars() returns the __dict__ attribute of the given object.
class Animal():
#instance attributes
def __init__(self1,name1,age):
self1.name= name1
self1.age=age
#instantiate the Animal class
tiger=Animal("Ronald",5) # tiger is an object of Animal class
print(vars(tiger)) # {'name': 'Ronald', 'age': 5}
Output
{'name': 'Ronald', 'age': 5}
if the object doesn't have __dict__ attribute then it will return TypeError
id=5
print(vars(id))
Output
TypeError Traceback (most recent call last)
in
1 id=5
----> 2 print(vars(id))
TypeError: vars() argument must have __dict__ attribute