Go language Variable Type

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

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.