Python vars() built-in function

From the Python 3 documentation

Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute.

Examples


class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
my_person = Person("Dwight", 35)

my_vars = vars(my_person)

print(my_vars)
# {'name': 'Dwight', 'age': 35}

Ups! Nothing here yet!

This is a great opportunity for you to collaborate! Hit the link at the end of this page and add some examples and a brief description. If you don't know where to start, the Python 3 documentation will lead you in the right direction.

Subscribe to pythoncheatsheet.org

Join 10.900+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.