代码点读机 / Python / __dict__

__dict__ Python · 特殊属性

返回对象属性名和值的字典。

怎么用

对象.__dict__

小例子

class 人:
    def __init__(self):
        self.名 = '赵六'
print(人().__dict__)

运行结果

{'名': '赵六'}

官方文档:https://docs.python.org/zh-cn/3/reference/datamodel.html

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条