services = ##定義字典
services['mysql'] = 3306 ##在字典中新增鍵為mysql,值為3306的鍵—值對
print(services)
services['http'] = 443 ##字典中有這個鍵—值對,則直接修改這個key對應的value值
print(services)
鍵—值對的排列順序與新增順序不同。python不關心鍵—值對 的新增順序,而只關心鍵和值之間的關聯關係。
update()方法新增多個鍵—值對
services = ##定義字典
services_backup = ##再定義乙個字典(要新增到上乙個字典裡的所有鍵—值對)
services.update(services_backup) ##新增
services = ##定義字典
services.update(flask=9000,http=8000) ##將要新增的鍵—值對直接寫成引數讀入到字典中
print(services)
setdefault()方式新增key值
對於字典中不再需要的資訊,可使用del 語句將相應的鍵—值對徹底刪除
使用del 語句時,必須指定字典名和要刪除的鍵
注意 :刪除的鍵—值對永遠消失了
pop()方法刪除指定key的鍵—值對
popitem()方法刪除最後乙個鍵—值對
clear()方法清空字典內容
字典中key值的檢視
字典中value值的檢視
字典中key—value值的檢視
字典中指定key的value值的檢視
方法get()
如果key值存在,返回value值
如果不存在,預設返回none,若需要指定返回值,傳值即可
遍歷字典中所有的鍵—值對
services =
for k in services:
print('key:',k,'value:',services[k])
oracle中新增刪除主鍵的方法
1 建立表的同時建立主鍵約束 1 無命名 create table student studentid int primary key not null,studentname varchar 8 age int 2 有命名 create table students studentid int s...
iptables檢視 新增 刪除規則
1 檢視 iptables nvl line number l 檢視當前表的所有規則,預設檢視的是filter表,如果要檢視nat表,可以加上 t nat引數 n 不對ip位址進行反查,加上這個引數顯示速度會快很多 v 輸出詳細資訊,包含通過該規則的資料報數量,總位元組數及相應的網路介面 line ...
python實現從字典中刪除元素的方法
python的字典可以通過del方法進行元素刪除,下面的 詳細演示了這一過程 create an empty dictionary d add an item d name fido assert d.has key name delete the item del d name assert no...