Go语言集合(Map)
生活随笔
收集整理的這篇文章主要介紹了
Go语言集合(Map)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package mainimport "fmt"func main (){var countryCaptiaMap map[string]string/*創建集合*/countryCaptiaMap =make(map[string]string)//10/*map中插入k-v對 ,各個國家的首都*/countryCaptiaMap["France"] = "Paris"countryCaptiaMap["Italy"] = "Rome"countryCaptiaMap["Japan"] = "tokyo"countryCaptiaMap["India"] = "New Delhi"/*使用key輸出map值*/for country :=range countryCaptiaMap{fmt.Println("Caption == ",country, "it`s ",countryCaptiaMap[country])}//20/*查看元素在集合中是否存在*/caption ,ok :=countryCaptiaMap["United States"]if(ok){fmt.Println("Caption of Unite States is", caption)}else {fmt.Println("不存在")}/*打印原始Map*///30for country := range countryCaptiaMap {fmt.Println("Caption of",country ,"is",countryCaptiaMap[country])}/*刪除元素*/delete (countryCaptiaMap, "France")/**打印現在的Map*/for country := range countryCaptiaMap {fmt.Println("Caption of",country ,"is",countryCaptiaMap[country])}
}
與50位技術專家面對面20年技術見證,附贈技術全景圖
與50位技術專家面對面20年技術見證,附贈技術全景圖
總結
以上是生活随笔為你收集整理的Go语言集合(Map)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Go语言范围(Range)
- 下一篇: 微信小程序 setData动态设置数组中