__dict__ is the dictionary attribute that exposes an object's stored instance attributes when that object has an attribute dictionary. Attribute names appear as keys, and their values appear as values. After a constructor assigns attributes, inspect the instance directly with task.__dict__. section 8.1.2 section 9.4.2
Inspecting constructor-created attributes
class Task: def __init__(self, title, desc, urgency): self.title = title self.desc = desc self.urgency = urgency task = Task("Laundry", "Wash clothes", 3) print(task.__dict__) # {'title': 'Laundry', 'desc': 'Wash clothes', 'urgency': 3} section 8.1.2
__dict__ also participates in ordinary instance-attribute lookup. When the dictionary contains a requested name, Python returns its value; when it does not, __getattr__ can provide a fallback. Leaving a lazy attribute unset allows that fallback to run, and setattr can cache the fetched value for later access. section 9.4.2
Use the dictionary representation deliberately:
- Inspect an instance's currently stored attributes while developing or debugging a class. section 8.1.2
- Copying task.__dict__ creates a dictionary snapshot, not another Task; the copied dictionary lacks class behavior such as save_data. section 10.3.1
- Prefer copy(task) when the goal is an independent object that retains the class's methods and behavior. section 10.3.1
