Go Language Details

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.