Dictionary additions and Deletions change
Dic1 ={"name": "Chun Sheng", "age": +, "sex": "Male"}
# dic1["Asdas"]= "DFDSF" add default Last
# Print (DIC1)
# dic1["Age"]=20//If a built-in value is overridden
# Print (DIC1)
#
# Dic1.setdefault ("weight")//with built-in values do not make any changes without adding a build value to
#dic1. SetDefault ("Weight", 150)//Add build value pair
#print (DIC1)
# Dic1.setdefault ("5", "5")
# Print (DIC1)
#删
# Print (Dic1.pop ("name"))///The return value is deleted as built
#print (Dic1.pop ("SSS", "None")) #//can set the return value
#print (DIC1)
#print (Dic1.popitem ()) #随机删除 There is a value in the returned value tuple that is deleted
# del dic1["name"]
# Print (DIC1)
# del dic1//delete list will be an error
# Print (DIC1)
# dic1.clear ()//Empty list
# Print (DIC1)
#改
# dic1["Name"]=1 #//Press Build to change
# Print (DIC1)
# dic={"name": "Jinag", "Age": "$", "sex": "Male"}
# dic2={"name": "Alex", "Weight": 75}
# dic.update (DIC2) #/////update changed
# Print (DIC)
# Print (DIC2)
#结果:
# {' name ': ' Jinag ', ' age ': ' + ', ' sex ': ' Male '}
# {' name ': ' Jinag ', ' weight ': *, ' age ': ' ' ', ' sex ': ' Male '}
#查
#print (Dic1.keys ()) #//
#print (Dic1.values ())//value
#print (Dic1.items ())//is a list inside is Ganso dict_items ([' Name ', ' Spring '), (' Age ', '), (' Sex ', ' male ')])
#
# for I in Dic1:
# print (i)//Cha Jian
# for I in Dic1.keys ():
# Print (i)
# for I in Dic1.values ()://Check value
# Print (i)
#面试题
# a,b=1,2
# a=1
# b=2
# A,b=b,a
# print (A, B)
Dictionary nesting
Build it up to find
In the go to delete and change to search
5th Day of Python Learning