python辞書の削除

3651 ワード

   2010-10-01,   .    ,         .
, .
:

 1 xiaoming_dict = {"name": "  "}
 2 
 3 #   
 4 print(xiaoming_dict["name"])
 5 #       ,  key   ,     
 6 # print(xiaoming_dict["name12"])
 7 
 8 #   /  
 9 #    key   ,      
10 xiaoming_dict["age"] = 26
11 xiaoming_dict["gender"] = "male"
12 #   key  ,          
13 xiaoming_dict["name"] = "  "
14 print(xiaoming_dict)
15 
16 #   
17 xiaoming_dict.pop("gender")
18 #          ,      
19 # xiaoming_dict.pop("gender12")
20 print(xiaoming_dict)

, , , . pop , KeyError, ?
xiaoming_dict["age"] = 26      xiaoming_dict =["age", 26].
, .