This is a creation in Article, where the information may have evolved or changed.
Arrays and strings are value types, slices, mappings, channels are value types, and assignments need to be noted.
1 Package Main2 3 Import (4 "FMT"5 )6 7 Func Main () {8 //Array9A1: = [3]int{1,2,3}TenA2: =A1 Onea2[0] =2 AFmt. PRINTLN (A1)//print:1 2 3 -Fmt. PRINTLN (A2)//Print:2 2 3 - //string theS1: ="123" -S2: =S1 -S2 ="223" -Fmt. Println (S1)//Print 123 +Fmt. PRINTLN (S2)//Print 223 - //slices +Slice1: = []int{1,2,3} ASlice2: =Slice1 atslice2[0] =2 -Fmt. Println (Slice1)//Print 2 2 3 -Fmt. Println (SLICE2)//Print 2 2 3 - //Map -M1: = Make (map[int]string) -m1[1] ="1" inM2: =M1 -m2[1] ="2" toFmt. PRINTLN (M1)//Print 1:2 +Fmt. Println (m2)//Print 1:2 - //Chan theC1: = Make (chanBOOL) *C2: =C1 $ go func () {Panax NotoginsengV: = <-C2 -Fmt. Println (v)//Print True the }() +C1 <-true A} View Code
Byte is of type Uint8, string is not []byte or []rune type]
1 Package Main2 3 Import (4 "FMT"5 )6 7 Func Main () {8S: ="Hello World"9 varIInterface{} =sTen One Switchi. (type) { A Case[]byte: -Fmt. Println ("string type is []byte") - Case[]rune: theFmt. Println ("string type is []rune") - Case[]int8: -Fmt. Println ("string type is []int8") - } + -Slice: = []byte{1,2} +i =Slice A Switchi. (type) { at Case[]uint8: -Fmt. Println ("byte is uint8")//Print - } -} View Code
Interface is a two-tuple of type and value, nil type is empty and value is empty
1 Package Main2 3 Import (4 "FMT"5 )6 7Func Truenil ()Interface{} {8 returnNil9 }Ten OneFunc Falsenil ()Interface{} { A varRET *int= Nil//This nil comes with a type - returnret - } the Func Main () { - ifTruenil () = =Nil { -Fmt. Println ("Truenil")//Print Truenil - } + - ifFalsenil () = =Nil { +Fmt. Println ("Falsenil")//No Print A } at} View Code