# 字典 dict {} # key:value形式存储 # 可以空字典 # value可以包含任何类型数据 # 逗号分隔键值对 # len()查看长度 # 字典无序,不按顺序输出 # 字典取值 字典[key] a = {"class": "python11", "student": 119, "teacher": "girl", "t_age": 20, "score": [90, 70, 80]} print(len(a)) print(a) print(a["score"]) # 删除 pop(key) 必须指定key res = a.pop("teacher") print(a) print(res) # 新增 a[新key]=value a["name"] = "lemon" print(a) # 修改 a[已有的key]=新的value a["t_age"] = 15 print(a) # 存在相同key时,最后key的值会覆盖前面的 # 不要存在相同的key # 存放不同数据类型时,使用字典 a = {"class": "python11", "student": 119, "teacher": "girl", "t_age": 20, "score": [90, 70, 80], "student": 125} print(a)