MAP(字典)在Python里的作用?
字典中的每一項(xiàng)都有一個(gè)鍵和一個(gè)對(duì)應(yīng)的值。你可以根據(jù)鍵找到值。
>>> favorite_sports = {'Ralph Williams' : 'Football','Michael Tippett' :'Basketball',
'Edward Elgar' : 'Baseball','Rebecca Clarke' : 'Netball','Ethel Smyth' : 'Badminton',
'Frank Bridge' : 'Rugby'}
>>> print(favorite_sports[‘Rebecca Clarke’]) #找到RebeccaClarke喜歡的運(yùn)動(dòng)
>>>del favorite_sports[‘Ethel Smyth’] #從字典中刪除EthelSmyth數(shù)據(jù)
>>>favorite_sports[‘Ethel Smyth’] = ‘Ice Hockey‘ #修改Ethel Smyth喜歡的運(yùn)動(dòng)
>>>favorite_sports[‘Can Can’]=‘tennis’ #追加cancan喜歡的項(xiàng)目
點(diǎn)擊加載更多評(píng)論>>