【发布时间】:2016-11-28 21:06:25
【问题描述】:
>>> a = object()
>>> a.x = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'x'
>>> b = lambda:0
>>> b.x = 5
>>> b.x
5
为什么object 类的实例没有__dict__,导致它表现为语义不可变?选择这种设计的原因是什么?
具体来说,为什么:
在 C 中定义的类型的实例没有 __dict__ 属性 默认。
如this question.中所述
【问题讨论】:
标签: python attributes immutability