一:删除健值对
outs = {'name': 'king', 'age': 25}
del outs['name']
print(outs) # {'age': 25}
二:遍历字典
1.遍历健值对
outs = {'name': 'king', 'age': 25}
for name, value in outs.items() :
print(name)
print(value)
2.遍历所有健
可以使用keys()方法,也可以直接遍历字典
outs = {'name': 'king', 'age': 25}
for name in outs.keys() :
print(name)
outs = {'name': 'king', 'age': 25}
for name in outs :
print(name)
3.遍历所有值
outs = {'name': 'king', 'age': 25}
for value in outs.values() :
print(value)
4.按顺序遍历
outs = {'name': 'king', 'age': 25}
for name in sorted(outs.keys()) :
print(name)