欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python中update的基本使用方法詳解

 更新時(shí)間:2019年07月17日 09:35:02   作者:南苑~春波  
這篇文章主要介紹了python中update的基本使用方法詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

前言

Python 字典 update()方法用于更新字典中的鍵/值對(duì),可以修改存在的鍵對(duì)應(yīng)的值,也可以添加新的鍵/值對(duì)到字典中。

語(yǔ)法格式

d.update(e)

參數(shù)說明

將e中鍵-值對(duì)添加到字典d中,e可能是字典,也可能是鍵-值對(duì)序列。詳見實(shí)例。

返回值

該方法沒有任何返回值。

實(shí)例

以下實(shí)例展示了 update() 方法的使用方法:

d = {‘one':1,'two':2}

d.update({‘three':3,'four':4}) # 傳一個(gè)字典 
print(d)

d.update(five=5,six=6) # 傳關(guān)鍵字 
print(d)

d.update([(‘seven',7),(‘eight',8)]) # 傳一個(gè)包含一個(gè)或多個(gè)元組的列表 
print(d)

d.update(([‘nice',9],[‘ten',10]))#傳一個(gè)包含一個(gè)或多個(gè)列表的元組 
print(d)

d.update(zip([‘eleven','twelve'],[11,12])) # 傳一個(gè)zip()函數(shù) 
print(d)

d.update(one=111,two=222) # 使用以上任意方法修改存在的鍵對(duì)應(yīng)的值 
print(d)

以上實(shí)例輸出結(jié)果為:

{‘one': 1, ‘four': 4, ‘three': 3, ‘two': 2} 
{‘one': 1, ‘four': 4, ‘three': 3, ‘five': 5, ‘two': 2, ‘six': 6} 
{‘seven': 7, ‘one': 1, ‘four': 4, ‘three': 3, ‘five': 5, ‘two': 2, ‘six': 6, ‘eight': 8} 
{‘seven': 7, ‘one': 1, ‘four': 4, ‘three': 3, ‘ten': 10, ‘five': 5, ‘nice': 9, ‘two': 2, ‘six': 6, ‘eight': 8} 
{‘one': 1, ‘four': 4, ‘three': 3, ‘twelve': 12, ‘ten': 10, ‘seven': 7, ‘six': 6, ‘eleven': 11, ‘two': 2, ‘nice': 9, ‘five': 5, ‘eight': 8} 
{‘one': 111, ‘four': 4, ‘three': 3, ‘twelve': 12, ‘ten': 10, ‘seven': 7, ‘six': 6, ‘eleven': 11, ‘two': 222, ‘nice': 9, ‘five': 5, ‘eight': 8}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論