vars()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jun 22, 2023
Contribute to Docs

vars() is a built-in Python function that returns the __dict__ attribute of an object. The __dict__ attribute is a dictionary containing the object’s mutable attributes.

Syntax

vars(object)

Here, object refers to an instance of a particular class.

Codebyte Example

The following example uses vars() to return the __dict__ attributes of the object Person:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy