class Computer:
def __init__(self) -> None:
self.modules = {"cpu":"intel", "内存":"镁光", "硬盘":"970-pro"}
self.moduleslist = []
@property
def modulesGetSetDel(self):
self.moduleslist.clear()
get_loops = [i for i in self.modules]
for ii in range(len(self.modules)):
self.moduleslist.append(get_loops[ii] + ": " + self.modules[get_loops[ii]])
return self.moduleslist
@modulesGetSetDel.setter
def modulesGetSetDel(self, key_value):
self.get_key_value_loops = [i for i in key_value]
for i in range(len(self.get_key_value_loops)):
self.modules[self.get_key_value_loops[i]] = key_value[self.get_key_value_loops[i]]
@modulesGetSetDel.deleter
def modulesGetSetDel(self):
for i in range(len(self.get_key_value_loops)):
del self.modules[self.get_key_value_loops[i]]
aa = Computer()
# #打印原始字典
print("原始字典数据: ", aa.modulesGetSetDel)
# #打印新增的字典
aa.modulesGetSetDel = {"机箱":"海盗船", "测试1":"测试11"}
print("新增字典数据: ", aa.modulesGetSetDel)
# 打印删除后的字典数据
del aa.modulesGetSetDel
print("删后字典数据: ", aa.modulesGetSetDel)