Python vars()
Preview: Anonymous contributor 1 total contribution
Anonymous contributor
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 usVisit usCodeHide codeOutputHide outputCopy to your clipboard
All contributors
- Preview: Anonymous contributor 1 total contribution
- Anonymous contributor
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
