一、现有字典info={'name':'大锤','hobby':'study','gender':1}
- 如何查看 name 对应值
- 发现年龄有误,应该是 20 岁,如何修改
- 现需要增加住址为杭州的信息
- 年龄每年都变化,现删除该信息
- 删除地址信息,并将删除的信息保存到日志【这里打印就可以】
- 现有 old_ dict={'name':'ww'}以及 new_dict={'name':'ww','birthday':'2008-05-20','gender':1},如何将new_dict 内容合并到 old_ dict 中
- 如何清空字典info的所有信息
- info[name],info.get(name)
- 因为没有发现年龄先增加一个年龄
Info[age]=12;修改lnfo[age]=20 - info[address]=’杭州’
- Del.info[age]
- print(info.pop(‘address’))
- new_dict.update(old_dict)
- info.clear(),##清空所有的条目
del,info ##删除词典
二、存储5本世界名著的七个信息:
每本书如何存储
5本书如何存储
books1={"name":"西游记","author":"章承恩","type":"神魔小说","Genre":"长篇小说","alias":"西游释厄传","Age of":"明朝","ForeignName":"The Journey to the West"}
books2={"name":"长安乱","author":"韩寒","type":"武侠小说","Genre":"长篇小说","alias":"null","Age of":"现代","ForeignName":"Chaos ChangAn"}
books3={"name":"悲惨世界","author":"雨果","type":"历史信仰","Genre":"长篇小说","alias":"null","Age of":"1862年","ForeignName":"Les Misérables"}
books4={"name":"三国演义","author":"罗贯中","type":"神魔小说","Genre":"长篇小说","alias":"三国志通俗演义、三国志演义","Age of":"元末明初洪武年间","ForeignName":"The Journey to the West"}
books5=dict([("name","红楼梦"),("author","曹雪芹等"),("type","人情小说"),("Genre","长篇小说"),("alias","石头记、情僧录、风月宝鉴、金陵十二钗、金玉缘"),("ForeignName","The Dream of Red Mansion")])遍历所有书的所有信息
储存所有书
books=[books1,books2,books3,books4,books5]
for i in books:
print(" ")
for y,s in i.items():
print(y,":",s)