__dict__: where Python stores attributes
Briefly

__dict__: where Python stores attributes
"Each of these class instances have a __dict__ attribute, which is a dictionary that actually stores the data that we'd normally look up on these objects: We can actually modify this dictionary in order to change the attributes on one of these objects: Note that you shouldn't do this. This is not something you're supposed to do in Python, but you can do it. And in fact, this is what Python does under the hood whenever you assign to an attribute on a class instance."
"Just like modules and class instances, classes also use a __dict__ attribute to store class attributes: Note that we're not looking at __dict__ on an instance of the Product class. We're looking at__dict__ on the class itself. You can see that our __init__ method and the display_price method are in this __dict__ dictionary. We often think of attributes and methods as completely distinct groups. But methods are also attributes. A methods is a function that lives on a class, which means it's also a class-level attribute."
Instance attributes live in each object's __dict__, a dictionary mapping attribute names to values. Assigning to an attribute updates that object's __dict__, and Python performs the same update internally. Modifying an object's __dict__ directly is possible but not recommended. Modules use a __dict__ to hold functions and constants such as pi, e, and tau. Classes maintain a __dict__ that stores class-level attributes, including functions that become methods. Methods are attributes because a method is a function on a class and therefore appears in the class's __dict__. The built-in vars(obj) returns an object's __dict__.
Read at Pythonmorsels
Unable to calculate read time
[
|
]