This is a creation in Article, where the information may have evolved or changed.
Code demo for Go language variable type
Basic_demo.go file
PackageMainImport("FMT")Const(I = -PI =3.1415PREFIX ="Go_")var(IintPifloat32Prefixstring)funcMain () {//Group declaration variables and ConstantsFmt. Println (i) fmt. Println (PREFIX)//one-dimensional arrayA: =[3]int{1,2,3} B: =[Ten]int{1,2,3} c: = [...]int{1,2,3} FMT. Println (A, B, c)//Two-D arraysDoublearray: =[2][4]int{[4]int{1,2,3,4},[4]int{5,6,7,8}} FMT. Println (doublearray) Easarray: =[2][4]int{{1,2,3,4},{5,6,7,8}} FMT. Println (Easarray)//dynamic array slice is not a true dynamic array, but a reference type. //And declare array, just less length //slice: = []byte{' A ', ' B ', ' C '} //Slice can be declared again from an array or an already existing slice varAR =[Ten]byte{' A ',' B ',' C ',' d ',' E ',' d '}varSlice1, Slice2 []byteSlice1 = AR[2: 5] Slice2 = AR[6:] Slice3: = ar[:] Slice4: = slice3[: 4] FMT. Printf ("%v,%v,%v", Slice1, Slice2, Slice3) fmt. Println (Slice4)//Dictionary map format is Map[keytype]valuetype //1. Direct Declaration //var numbers map[string] int //2. A short map declaration method //numbers: = Make (Map[string]int) //numbers["one"] = 1 //numbers["both"] = 2Numbers: =Map[string]int{"One":1,"both":2} FMT. PRINTLN (Numbers)//Find out if there is a corresponding key value if_, OK: = numbers["One"]; OK {fmt. Println ("There is a key value of one's value pair!") }//Delete the value of the specified key Delete(Numbers,"both") FMT. PRINTLN (Numbers)//The default value before the variable is not populated, "0 value" //Int,int8,int32,int64,rune (actual type of Rune is Int32), Float32,float64-0 //UINT byte (the actual type of byte is Uint8)--0x0 //BOOL ---false //String--""}