map _ golang
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 : .......
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。