1.认识字典
#字典:{}里面有键值对,各个键值对之间用逗号隔开
dict1={'name':'tom','age':'20','gender':'男'}
print(dict1)
#创建空字典
dict2=dict()
print(type(dict2))
dict3={}
print(type(dict3))
2.字典常用操作—增
dict1={'name':'tom','age':'20','gender':'男'}
#新增键值对-增加ID
dict1['id']=110
print(dict1)
dict1['name']='rose'
print(dict1)#注意:减name的值变为了rose 说明字典是可以改变的数据序列
3.字典常用操作-删
#删除字典元素
#del()&clear()
dict1={'name':'tom','age':'20','gender':'男'}
#用法一
del dict1['name']
print(dict1)
#用法二
del(dict1['gender'])
print(dict1)
#清空字典
dict1.clear()
print(dict1)
字典查找数据——按照key查找
#还有按照函函数超找数据,在下节总结
dict1={'name':'tom','age':'20','gender':'男'}
print(dict1['name'])#按key值查找