vars()

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

All Built in Functions in Python Class Object & Methods
Subscribe to our YouTube Channel here

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer