python修改字典內(nèi)key對(duì)應(yīng)值的方法
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 14:42:11
python修改字典內(nèi)key對(duì)應(yīng)值的方法
python修改字典內(nèi)key對(duì)應(yīng)值的方法:本文實(shí)例講述了python修改字典內(nèi)key對(duì)應(yīng)值的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: d2 = {'spam': 2, 'ham': 1, 'eggs': 3} # make a dictionary print d2 # order is scrambled d2['ham'] = ['grill',
導(dǎo)讀python修改字典內(nèi)key對(duì)應(yīng)值的方法:本文實(shí)例講述了python修改字典內(nèi)key對(duì)應(yīng)值的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: d2 = {'spam': 2, 'ham': 1, 'eggs': 3} # make a dictionary print d2 # order is scrambled d2['ham'] = ['grill',

本文實(shí)例講述了python修改字典內(nèi)key對(duì)應(yīng)值的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
d2 = {'spam': 2, 'ham': 1, 'eggs': 3} # make a dictionary
print d2 # order is scrambled
d2['ham'] = ['grill', 'bake', 'fry'] # change entry
print d2
運(yùn)行結(jié)果如下:
{'eggs': 3, 'ham': 1, 'spam': 2}
{'eggs': 3, 'ham': ['grill', 'bake', 'fry'], 'spam': 2}
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
python修改字典內(nèi)key對(duì)應(yīng)值的方法
python修改字典內(nèi)key對(duì)應(yīng)值的方法:本文實(shí)例講述了python修改字典內(nèi)key對(duì)應(yīng)值的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: d2 = {'spam': 2, 'ham': 1, 'eggs': 3} # make a dictionary print d2 # order is scrambled d2['ham'] = ['grill',