码迷,mamicode.com
首页 > 其他好文 > 详细

map _ golang

时间:2015-03-13 16:16:07      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

Maps are Go‘s built-in associative data type(sometimes called hashes or dits in other languages)

package main

import (
    "fmt"
)

func main() {

    m := make(map[string]int)

    m["k1"] = 7
    m["k2"] = 13

    fmt.Println("map :", m)

    v1 := m["k1"]
    fmt.Println("v1 :", v1)

    fmt.Println("len : ", len(m))

    delete(m, "k2")
    fmt.Println("map:", m)

    a, prs := m["k2"]
    fmt.Println("prs:", prs, a)

    n := map[string]int{"foo": 1, "bar": 2}
    fmt.Println("map:", n)
}
map : map[k1:7 k2:13]
v1 : 7
len :  2
map: map[k1:7]
prs: false 0
map: map[foo:1 bar:2]

  总结 :

    1 : 奇怪的构造方法 m := make(map[string]int)

    2 : .......

map _ golang

标签:

原文地址:http://www.cnblogs.com/jackkiexu/p/4335139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!