思维导图如下

python字典的操作-LMLPHP

1、字典的增加

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

python字典的操作-LMLPHP

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字典的操作-LMLPHP

3、字典的更改

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

python字典的操作-LMLPHP

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字典的操作-LMLPHP

05-04 01:40