class _ActionsContainer(object): def __init__(self): self._registries = {} def register(self, registry_name, value, object): registry = self._registries.setdefault(registry_name, {}) #此处setdefault参数相当于key,vaule,最终返回value,次value与registry共享内存 print(registry) print(self._registries) registry[value] = object if __name__ == '__main__': action = _ActionsContainer() action.register('action', None, 'xxx') #打印结果?