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’]

发布了36 篇原创文章 · 获赞 0 · 访问量 9143

猜你喜欢

转载自blog.csdn.net/eliuxiaoming1/article/details/85255764