show inline map initialization
This commit is contained in:
parent
c852c887d7
commit
4549dbcaca
@ -29,7 +29,7 @@ func main() {
|
|||||||
fmt.Println("dcl:", y)
|
fmt.Println("dcl:", y)
|
||||||
|
|
||||||
// The builtin `len` returns the length of an array.
|
// The builtin `len` returns the length of an array.
|
||||||
fmt.Println("len:", len(x))
|
fmt.Println("len:", len(y))
|
||||||
|
|
||||||
// Array types are one-dimensional, but you can
|
// Array types are one-dimensional, but you can
|
||||||
// compose types to build multi-dimensional data
|
// compose types to build multi-dimensional data
|
||||||
|
@ -41,4 +41,9 @@ func main() {
|
|||||||
// like `0` or `""`.
|
// like `0` or `""`.
|
||||||
_, prs := m["k2"]
|
_, prs := m["k2"]
|
||||||
fmt.Println("prs:", prs)
|
fmt.Println("prs:", prs)
|
||||||
|
|
||||||
|
// You can also declare and initialize a new map in
|
||||||
|
// the same line with this syntax.
|
||||||
|
n := map[string]int{"foo": 1, "bar": 2}
|
||||||
|
fmt.Println("map:", n)
|
||||||
}
|
}
|
||||||
|
@ -6,3 +6,4 @@ v1: 7
|
|||||||
len: 2
|
len: 2
|
||||||
map: map[k1:7]
|
map: map[k1:7]
|
||||||
prs: false
|
prs: false
|
||||||
|
map: map[foo:1 bar:2]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user