字典
字典知识图谱
![字典部分知识点框图](https://img-blog.csdnimg.cn/20200731183730752.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L251bWJlcjM0MDI=,size_16,color_FFFFFF,t_70#pic_center)
代码实践
判断数据类型是否为可变类型
i = 1
print(id(i),type(i))
i += 2
print(id(i))
print(hash(i))
"""
1867415664 <class 'int'>
1867415728
3
"""
j = {
1:'python',2:'show'}
print(id(j))
j[3]='jack'
print(id(j))
print(hash(j))
"""
2508811916272
2508811916272
TypeError: unhashable type: 'dict'
"""
字典的创建
dic = {
1:'123',2:'234','3':'345'}
seq1 = ['甲鱼哥','章鱼弟','龙虾仔']
dic1 = dict.fromkeys(seq1,(1,2,3))
print(dic)
print(dic1)
dic2 = dict(name1 = 'I', name2 = 'love',name3 = 'python')
print(dic2)
"""
{1: '123', 2: '234', '3': '345'}
{'甲鱼哥': (1, 2, 3), '章鱼弟': (1, 2, 3), '龙虾仔': (1, 2, 3)}
{'name1': 'I', 'name2': 'love', 'name3': 'python'}
"""
字典内置方法
dic = {
1:'甲鱼哥',2:'章鱼弟',3:'龙虾仔'}
print(dic.keys(),dic.values(),dic.items())
dic[4] = '海小绵'
print(dic)
dic1 = {
3:'龙虾仔仔'}
dic.update(dic1)
print(dic)
x = dic.popitem()
print