python __dict__解释

In python, each instance of a Class or any other Object, such as integer, string, list has a attribute _dict_. It stores the writable attributes of this object.
>>> class A():
… def init(self):
… self.x=“xstring”
… self.y=“ystring”
… def show_dict(self):
… print(self.dict)

>>> x=A()
>>> x.show_dict()
{‘x’: ‘xstring’, ‘y’: ‘ystring’}
>>> dir(x)
[‘class’, ‘delattr’, ‘dict’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘gt’, ‘hash’, ‘init’, ‘init_subclass’, ‘le’, ‘lt’, ‘module’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘weakref’, ‘show_dict’, ‘x’, ‘y’]

你可能感兴趣的:(python __dict__解释)