Python vars()

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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

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:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours