字典
# 字典是python基本数据结构之一,相对于列表和元组,他是无序的,每次输出都打乱了顺序,没有下标hello={110:{"name":"alex","age":28,"home":"shandong"},111:{"name":"ada","age":28,"home":"pk"},112:{"name":"simon","age":28,"home":"hz"},113:{"name":"kevin","age":28,"home":"gz"}
}print(hello.items())
hello2={110:{"id":"37232320000000"}
}# 增
# 相比于元组和列表,字典没有append方法# 删,字典没有remove方法,只有pop 和del方法
pop = hello.pop(110)
print(pop)
# 返回值是被删掉的值
del hello[112]
print("del 112 after:",hello)# 改hello[113][3]="he0llo"
print(hello[113])
hello[222]="mike"# 查
print(222 in hello) #返回True,经常被用于判断在字典存在不存在一个键
print(hello.keys()) #以列表形式返回所有的的键,没有值
print(hello.values()) #以列表返回所有字典的值,没有键
for i in hello.values():print(i,end='')# 更新,将字典合并了,hello包含hello和hello2的所有元素
hello.update(hello2)
print(hello)# 循环键和值
for i in hello:print(i,hello[i])for k,v in hello.items():print(k,v)# 综合以上比较,
# 字典对象.keys() #以列表形式返回所有的的键,没有值
# 字典对象.values() #以列表返回所有字典的值,没有键(另外在Django orm 中,models.table.objects.values()是元组,values_list是字典)
# 字典对象.items() 以列表返回键和值组成的元组,因此for循环k,v可以取出键和值