查字典:
name = [["a",23,"yue"],["b",26,"bnt"],["cd",35,"by"],]
print(name.index(["a",23,"yue"])) #要全部输入才能查到,不能只输入部分字符
name = {
123:{"age":33,"name":"alex"},
234:{"age":52,"name":"nuy"},
345:["liu"],
}
print(name[345]) #茶字典
print(name[123]["name"]) #茶字典具体的姓名
#字典的特点:
#1、key是唯一的
#2、数据必须是无序的
#改
name[345][0]="jensen"
print(name)
#追加
name[345].append("xie")
print(name)
#插入
name[222]="mike"
print(name)
#删
print(name.pop(345,None)) #删除指定的key,如果没有那个key,返回none
print(name)
print(name.popitem()) #随机删除某个数据
print(name)
name.pop(345,None)
name.popitem
del name[222] #删除
#查
print(name.get(123)) #看是否存在某个ID
print(123
in name) #看是否存在某个key
#循环
for i in name:
print(i,name[i])
for i in name.items():
print(i)
for k,v in name.items(): #不要用,效率不高
print(i)
#更新
name = {
123:{"age":33,"name":"alex"},
234:{"age":52,"name":"nuy"},
345:["liu"],
}
dic2={
345:{"age":23,"name":"yy"},
456:{"age":45,"name":"zz"},
}
name.update(dic2) #更新字典:对于同样key,用新的,没有的key,就添加
print(name)