python字典之增删改查

 1 # Author:yebo
 2 
 3 info = {
 4     'stu01':"yebo",
 5     'stu02':"shuz",
 6     'stu03':"yomi"
 7 }
 8 
 9 
10 #
11 info['stu01'] = "松江小旋风"
12 
13 #
14 info['stu04'] = "7zai"
15 print(info)
16 
17 #
18 info.pop('stu02')
19 print(info)
20 
21 #
22 print(info.get('stu01'))
23 print('stu01' in info)   #判断有无此key值
24 
25 #循环打印
26 for i in info:
27     print(i,info[i])   #法一,更好
28 
29 for k,v in info.items():
30     print(k,v)   #法二

猜你喜欢

转载自www.cnblogs.com/SongjiangCyclone/p/9375469.html