Map map

 

Mapping is the python in the dictionary

 

. 1  Package main
 2  
. 3 Import " FMT " 
. 4  
. 5  FUNC main () {
 . 6  
. 7      / * 
. 8      defined string is a bond int numeric
 . 9      var XX Map [string] int = Map [string] int {}
 10      var XX = Map [ String] {} int
 . 11      XX: = Map [String] int {}
 12 is       * / 
13 is  
14  
15  
16      // length is not specified, a default length is 0
 . 17      // A: = the make (Map [String] int, 2) 
18 is      A: = the make (Map [ String ] int )
 . 19  
20 is  
21 is  
22 is      //Adding data 
23 is      A [ " AAA " ] = . 1 
24      A [ " BBB " ] = 2 
25      A [ " CCC " ] = . 3 
26 is  
27  
28      // The key to access the value 
29      fmt.Println ( " AAA number is " , a [ " aaa " ])   // number aaa is 1
 30  
31 is  
32  
33 is      // change the value 
34 is      a [ " aaa " ] = 111 
35     fmt.Println ( " AAA number is " , A [ " AAA " ])   // AAA number was 111. 
36  
37 [  
38 is  
39  
40 }

 

 

Key with parity

 

. 1  Package main
 2  
. 3 Import " FMT " 
. 4  
. 5  FUNC main () {
 . 6  
. 7      A: = the make (Map [ String ] int )
 . 8  
. 9  
10  
. 11      // add data 
12 is      A [ " AAA " ] = . 1 
13 is      A [ " BBB " ] = 2 
14      a [ " CCC " ] = . 3 
15  
16      // If the query does not exist, is not given. 
17      fmt.Println (" Ddd number is " , A [ " ddd " ])   // ddd numbers 0
 18 is  
. 19  
20 is      // access key with the authentication determination is then made 01 
21 is      AA, OK: A = [ " AAA " ]
 22 is      IF OK == to true {
 23 is          fmt.Println ( " value is aaa " , AA)
 24      } the else {
 25          fmt.Println ( " the value is not " )
 26      }
 27  
28  
29      // check sum, logical judgment made 02
30      IF AAA, OK: A = [ " ddd " ]; == OK to true {
 31 is          fmt.Println (AAA)
 32      } the else {
 33 is          fmt.Println ( " no " )
 34      }
 35  
36  
37 [  
38 is      // traversal key and 01 values 
39      for key, value: = Range A {
 40          fmt.Printf ( " A [% S] D =% \ n- " , key, value)
 41 is      }
 42 is  
43 is  
44 is      /// traversal key 02 and values 
45     for key := range a{
46         fmt.Println(key,a[key])
47     }
48 
49 }

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/chaoyangxu/p/11859127.html
Map
Map
map
map