美文网首页
Map-参考答案

Map-参考答案

作者: tonyemail_st | 来源:发表于2018-06-18 21:21 被阅读0次
    package main
    
    import (
        "fmt"
    )
    
    func main(){
        var countryCapitalMap map[string]string =
            map[string]string{"France": "Paris",    "Italy": "Rome",
            "Japan": "Tokyo", "India": "New Delhi"}
        //countryCapitalMap = make(map[string]string)
        //countryCapitalMap["France"] = "Paris"
        //countryCapitalMap["Italy"] = "Rome"
        //countryCapitalMap["Japan"] = "Tokyo"
        //countryCapitalMap["India"] = "New Delhi"
    
        for country := range countryCapitalMap{
            fmt.Println(country, "首都是:", countryCapitalMap[country])
        }
    
        capital, ok := countryCapitalMap["USA"]
        if (ok) {
            fmt.Println("the capital of USA is: ", capital)
        }else{
            fmt.Println("not exist")
        }
    
        delete(countryCapitalMap, "France")
        fmt.Println(countryCapitalMap)
    
    }
    

    相关文章

      网友评论

          本文标题:Map-参考答案

          本文链接:https://www.haomeiwen.com/subject/gkqoeftx.html