change
= {DIC1 ' Age ' : 16, ' name ' : ' sets you elephant ' , ' Sex ' : ' , MALE ' , ' weight ' : ' 67 ' } DIC2 = { ' Age ' : 45, ' Sex ' : ' , MALE ' } dic2.update (DIC1) # update data in the dict1 dict2 in a change is not added Print (DIC1) Print (DIC2)
= {DIC1 ' Age ' : 16, ' name ' : ' sets you elephant ' , ' Sex ' : ' , MALE ' , ' weight ' : ' 67 ' } DIC1 [ ' Age ' ] = ' . 19 ' Print (DIC1 )
check
= {DIC1 ' Age ' : 16, ' name ' : ' sets you elephant ' , ' Sex ' : ' , MALE ' , ' weight ' : ' 67 ' } Print (dic1.keys ()) # key Print (DIC1 .items ()) # value Print (dic1.values ()) # tuple, the tuple contains key values
= {DIC1 ' Age ' : 16, ' name ' : ' sets you elephant ' , ' Sex ' : ' , MALE ' , ' weight ' : ' 67 ' } # Print (dic1.keys ()) # key # Print (dic1.items ()) # value # Print (dic1.values ()) # tuple, the tuple contains key values for I in dic1.values (): Print (I)
You can also use a for loop to query, similar to the other two.
= {DIC1 ' Age ' : 16, ' name ' : ' sets you elephant ' , ' Sex ' : ' , MALE ' , ' weight ' : ' 67 ' } L = DIC1 [ ' Age ' ] # direct return value, However, if the key is not in the dictionary, it will error Print (L)