sh_10_ use basic dictionary

 

sh_10_ use basic dictionary

= {xiaoming_dict " name " : " Bob " } 

# 1. Value 
Print (xiaoming_dict [ " name " ])
 # when the value, if the specified key does not exist, the program will be given! 
# Print (xiaoming_dict [ "name123"]) 

# 2. Add / modify 
# If key does not exist, the new key-value pair 
xiaoming_dict [ " Age " ] = 18 is
 # If a key is present, will modify the existing key pair 
xiaoming_dict [ " name " ] = " little Ming " 

# 3. delete 
xiaoming_dict.pop ( "" )
 # When deleting the specified key-value pairs, if the specified key does not exist, the program will complain! 
# Xiaoming_dict.pop (" name123 ") 

Print (xiaoming_dict)

 

Guess you like

Origin www.cnblogs.com/shaohan/p/11519362.html