写一个字典
#!/usr/bin/env python Contact_list = { ‘beijing‘ : ‘01‘, ‘tianjin‘ : ‘02‘, ‘chongqing‘ : ‘03‘, ‘guangzhou‘ : ‘04‘, ‘xian‘ : ‘05‘ } print Contact_list
查字典
print Contact_list[‘beijing‘]
添加字典中的一个元素
Contact_list[‘qingdao‘] = ‘06‘
循环遍历字典
#!/usr/bin/env python Contact_list = { ‘beijing‘ : ‘01‘, ‘tianjin‘ : ‘02‘, ‘chongqing‘ : ‘03‘, ‘guangzhou‘ : ‘04‘, ‘xian‘ : ‘05‘ } #print Contact_list[‘beijing‘] #Contact_list[‘qingdao‘] = ‘06‘ #print Contact.keys() #print Contact.values() #print Contact_list for k,v in Contact_list.items(): print k,v
时间: 2024-11-10 07:13:50