VOOZH about

URL: https://www.codecademy.com/resources/docs/python/built-in-functions/vars

⇱ Python | Built-in Functions | vars() | Codecademy


Skip to Content

Python vars()

Preview: Anonymous contributor 1 total contribution
Anonymous contributor

1 total contribution

Published Jun 22, 2023

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 CoursesIncludes 6 Courses
    • With Professional CertificationWith Professional Certification
    • Beginner Friendly.
      75 hours75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With CertificateWith Certificate
    • Beginner Friendly.
      24 hours24 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:

Visit us
Visit us
Hide code
Code
Output
Hide output
Copy to your clipboard

All contributors

Learn Python on Codecademy

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