Working With Python's .__dict__ Attribute

Steven Loyens
Steven Loyens 10 Lessons 34m advanced python

Python’s .__dict__ is a special attribute in classes and instances that acts as a namespace, mapping attribute names to their corresponding values. You can use .__dict__ to inspect, modify, add, or delete attributes dynamically, which makes it a versatile tool for metaprogramming and debugging.

In this video course, you’ll learn about using .__dict__ in various contexts, including classes, instances, and functions. You’ll also explore its role in inheritance with practical examples and comparisons to other tools for manipulating attributes.

By the end of this video course, you’ll understand that:

  • .__dict__ holds an object’s writable attributes, allowing for dynamic manipulation and introspection.
  • Both vars() and .__dict__ let you inspect an object’s attributes. The .__dict__ attribute gives you direct access to the object’s namespace, while the vars() function returns the object’s .__dict__.
  • Common use cases of .__dict__ include dynamic attribute management, introspection, serialization, and debugging in Python applications.

What’s Included:

  • 10 Lessons
  • Video Subtitles and Full Transcripts
  • 2 Downloadable Resources
  • Accompanying Text-Based Tutorial
  • Interactive Quiz to Check Your Progress
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

About Steven Loyens

Steven is an Actuary, Economist and Engineer who found his passion for coding messing about with his Commodore 64 in the eighties. He loves understanding how things work and sharing that knowledge. He's an experienced coach and mentor.

» More about Steven

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Related Courses:

← Browse All Courses