与C艹相同,map有key值和value值,在这里,在value的访问中key值完全相当于一个下标。不费口舌了,上代码!
favoriate_sports = {'Tom' : 'football', 'Marry' : 'swim', 'Edward' : 'playing overwatch'}
print('Tom\'s favoriate sport is %s' % favoriate_sports['Tom'])
print(favoriate_sports)
favoriate_sports['Edward'] = 'coding'
print(favoriate_sports)
del favoriate_sports['Marry']
print(favoriate_sports)
输出结果
Tom's favoriate sport is football
{'Tom': 'football', 'Marry': 'swim', 'Edward': 'playing overwatch'}
{'Tom': 'football', 'Marry': 'swim', 'Edward': 'coding'}
{'Tom': 'football', 'Edward': 'coding'}
样例中包含了字典的创建、访问、修改和删除,相关格式,见样例233,溜了遛了。
等等,map改成dict一样用。
再等会,还有,两个字典不能相加。