golang arrays, slices, maps finishing [I] ing in the country chart

main Package 

Import "FMT"

/ *
array is important to build, and to develop an array defined length and data type arr [10] int
after a fixed array of not adding any
* /


/ *
sections: an array is arbitrary cut
slices are the underlying array in a continuous segments, continuous attention means that slice can not "jump assignment", sliced flexible than the array, the array elements can not arbitrarily add
slices can add, delete, copy sections element slice may be considered lightweight an array of wrapper
sections stated: make keyword make ([] string, 2) , may be added by the slice append to the end, can only be accessed through the index value
* /

/ *
mapping: kv is the mode key array may be access by key value
stated: the make (Map [String] int)
golang static language, because the dynamic mapping function like a python language, C language, one of the areas not

* /

FUNC main () {
// var ARR [ 2] String
// var of arr1 [10] int
// var arr2 is [] int
// var ARR3 [] String
// ARR [0] = "Hello"
// ARR [. 1] = "World"
//fmt.Println(arr, of arr1, arr2 is, ARR3)

// buildSlice ()
the buildMap ()
}

FUNC buildSlice () {
var ARR = the make ([] String, 2)
ARR [0] = "Hello"
ARR [. 1 ] = "world" // section is continuous here, not directly to arr [10] assignment
arr = append (arr, "china ") // append additional value to the slice
ARR = the append (ARR, "china1")
ARR the append = (arr, "china2")
arr = the append (arr, "china3", "china4", "china5")
arr = the append (arr [: 3]) // delete section, only the first three elements to obtain slices
the make tt = var ([] String,. 1)
copy (tt, ARR) // replication sections, and to copy only the length tt
fmt.Println (ARR, tt)
}

FUNC the buildMap () {
var tt = the make (Map [ String] int)
TT [ "name"] = 10
TT [ "Age"] = // additive element 21 is
// delete (tt, "age" ); // remove elements
fmt.Println (tt, tt [ "name"])
}

Guess you like

Origin www.cnblogs.com/iifeng/p/11486259.html