python字典的操作

思维导图如下

python字典的操作

1、字典的增加

    dic1={'name':'wujie','age':18,'gender':'男'}
dic1['profession']='python全栈'
dic1.setdefault('hobby','游戏')
print(dic1)

python字典的操作

2、字典的删除

dic1={'name':'wujie','age':18,'gender':'男'}
dic1['profession']='python全栈'
dic1.setdefault('hobby','游戏')
# print(dic1)
# 删
dic1.pop('age')
dic1.popitem()
del dic1['name']
print(dic1)

python字典的操作

3、字典的更改

    dic1 = {'name': 'wujie', 'age': 18, 'gender': '男'}
dic2 = {'name': 'wushuai', 'age': 18, 'gender': '男','hobby':'游戏'}
dic2.update(dic1)
print(dic2)

python字典的操作

4、字典的查询

    dic1 = {'name': 'wujie', 'age': 18, 'gender': '男'}
print(dic1.keys())
print(dic1.values())
print(dic1.items())
for k,v in dic1.items():
print(k,v)

python字典的操作

上一篇:mybatis错误:Invalid bound statement (not found)


下一篇:python图像处理之PIL库