为内置类存储的键/值数据在哪里?它们不能通过“__dict__”访问,因为它们不被视为属性。
示例:
class TestNewClass(dict):
def __init__(self, a, b, c):
self.a = a
self.b = b
self["item"] = c
x = TestNewClass(3, 4, 5)
print(x.a) # 3
print(x.b) # 4
print(x["item"]) # 5
print(x.__dict__) # {"a": 3, "b": 4} c not considered an attribute